This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private int _lives = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Damage(int dmg) | |
{ | |
_lives -= dmg; | |
if (_lives < 0) | |
GameObject.Destroy(this.gameObject); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (collision.tag == "Player") | |
{ | |
Player player = collision.GetComponent<Player>(); | |
if (player != null) | |
player.Damage(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ComponentClass component = gameObjectVariable.GetComponent<ComponentClass>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator MyRoutine(){ | |
//do something, maybe repeatedly | |
yield return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator MyOtherRoutine(){ | |
//stuff to do | |
yield return new WaitForSeconds(3f); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StartCoroutine(MyRoutine()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private float _rate = 5f; | |
[SerializeField] | |
private GameObject _enemyContainer, _enemyPrefab; | |
private Vector3 _position = Vector3.zero; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator SpawnEnemy(float rate) | |
{ | |
while (true) | |
{ | |
Instantiate(_enemyPrefab, _position, Quaternion.identity) | |
.transform.SetParent(_enemyContainer.transform); | |
yield return new WaitForSeconds(rate); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Start() | |
{ | |
StartCoroutine(SpawnEnemy(_rate)); | |
} |
OlderNewer