How to run a function every time the object the script is attached to gets set to active.

I have it set up like this:

  1. Enemy get destroyed
  2. GUI pops up
  3. The script that is attached to the GUI tells it to wait for 2 seconds and then disable itself.

The problem is, I don’t know how start a function as soon as the object is SetActive. I’ve tried the Start function of course (as seen below) but when the object gets enabled for a second time the Start function does not run again.

#pragma strict

var delay : float = 2;

function Start ()
{
    yield WaitForSeconds(delay);
    gameObject.SetActive(false);   
}
1 Like
6 Likes

Thanks