- Home /
Question by
delfinatarga · Nov 12, 2017 at 03:41 PM ·
coroutineimagespawnnot working
Coroutine not working?
Hello! 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);
}
}
Comment
You should call image.enabled = false;
after calling yield return new WaitForSeconds (t);
Your answer

Follow this Question
Related Questions
spawn timer problem 2 Answers
Changing multiple UI.Image source image downloaded via WWW class 0 Answers
StopCoroutine with IEnumerator not working 2 Answers
Why is unity exiting a loop inside a coroutine after its first run through? 1 Answer
How to make the Colour parameter in coroutine work with any anything with a colour variable. 2 Answers