Skip to main content
Bumped by Community user
Bumped by Community user
Fixed the code block and some minor mistakes
Source Link
John Hamilton
  • 3.1k
  • 1
  • 17
  • 34

I made this code because i needI needed an image to display a couple seconds after an enemy spawns, but for some reason iI can't make it work.

There's no error in the console, but it doesn't display the image and iI don't know what to do. Here's my script (it's attached to the enemy prefab)

 public class enemyAttack : MonoBehaviour {

 public float time = 5f;
 private IEnumerator coroutine;    
 public Image image; 
 private float t = 5f;

 void Start ()
 {
     //image.gameObject.SetActive (false);
     image.enabled = false;
     coroutine = nombredeCorutina (time, image); 
     StartCoroutine (coroutine);
 }

 private IEnumerator nombredeCorutina (float t, Image im)
 {

     image.enabled = true;
     //im.gameObject.SetActive (true);
     yield return new WaitForSeconds (t);

     coroutine = nombredeCorutina (time, im);
     StartCoroutine (coroutine);
 }
}

}

I made this code because i need an image to display a couple seconds after an enemy spawns, but for some reason i can't make it work.

There's no error in the console, but it doesn't display the image and i don't know what to do. Here's my script (it's attached to the enemy prefab)

 public class enemyAttack : MonoBehaviour {

 public float time = 5f;
 private IEnumerator coroutine;    
 public Image image; 
 private float t = 5f;

 void Start ()
 {
     //image.gameObject.SetActive (false);
     image.enabled = false;
     coroutine = nombredeCorutina (time, image); 
     StartCoroutine (coroutine);
 }

 private IEnumerator nombredeCorutina (float t, Image im)
 {

     image.enabled = true;
     //im.gameObject.SetActive (true);
     yield return new WaitForSeconds (t);

     coroutine = nombredeCorutina (time, im);
     StartCoroutine (coroutine);
 }

}

I made this code because I needed an image to display a couple seconds after an enemy spawns, but for some reason I can't make it work.

There's no error in the console, but it doesn't display the image and I don't know what to do. Here's my script (it's attached to the enemy prefab)

 public class enemyAttack : MonoBehaviour {

 public float time = 5f;
 private IEnumerator coroutine;    
 public Image image; 
 private float t = 5f;

 void Start ()
 {
     //image.gameObject.SetActive (false);
     image.enabled = false;
     coroutine = nombredeCorutina (time, image); 
     StartCoroutine (coroutine);
 }

 private IEnumerator nombredeCorutina (float t, Image im)
 {

     image.enabled = true;
     //im.gameObject.SetActive (true);
     yield return new WaitForSeconds (t);

     coroutine = nombredeCorutina (time, im);
     StartCoroutine (coroutine);
 }
}
Source Link

Coroutine not working (Unity)

I made this code because i need an image to display a couple seconds after an enemy spawns, but for some reason i can't make it work.

There's no error in the console, but it doesn't display the image and i don't know what to do. Here's my script (it's attached to the enemy prefab)

 public class enemyAttack : MonoBehaviour {

 public float time = 5f;
 private IEnumerator coroutine;    
 public Image image; 
 private float t = 5f;

 void Start ()
 {
     //image.gameObject.SetActive (false);
     image.enabled = false;
     coroutine = nombredeCorutina (time, image); 
     StartCoroutine (coroutine);
 }

 private IEnumerator nombredeCorutina (float t, Image im)
 {

     image.enabled = true;
     //im.gameObject.SetActive (true);
     yield return new WaitForSeconds (t);

     coroutine = nombredeCorutina (time, im);
     StartCoroutine (coroutine);
 }

}