I have a shooting game, in which four enemies appear by sequence one after another. What happens is that only the first enemy appear, and others don't appear until i check one of them as active during run the others become active too. Here is the code:-
void Awake () {
enemy [1].SetActive(false);
enemy [2].SetActive(false);
enemy [3].SetActive(false);
}
void Start()
{
enemy [0].SetActive(true);
StartCoroutine (Wait ());
StartCoroutine (Wait1 ());
StartCoroutine (Wait2 ());
}
void Update() {
InvokeRepeating ("Wait", 3f, 4f);
InvokeRepeating ("Wait1", 3f, 5f);
InvokeRepeating ("Wait2", 3f, 6f);
}
IEnumerator Wait() {
yield return new WaitForSeconds (2f);
enemy [1].SetActive(true);
}
IEnumerator Wait1() {
yield return new WaitForSeconds (3f);
enemy [2].SetActive(true);
}
IEnumerator Wait2() {
yield return new WaitForSeconds (5f);
enemy [3].SetActive(true);
}
↧