game object active after certain time :)

how can i make a game object active after certain amount of time?..i know its easy for u pros :stuck_out_tongue:
thanks!

You will need to have a reference to it in another script and put the timer there. Once the timer is reached, it can be activated from there too.

so u mean like make a script with a timer and if the timer reaches to 0 make another script with “gameObject.active=true;”?

Let’s say you have this in your playerCollision script in the OnTriggerEnter function…

function OnTriggerEnter(collisionInfo : Collider)
{
if (collisionInfo.gameObject.tag == “ball1_TRIGGER”) // This is the trigger object that turns the ball1 off and back on"
{
var objectTHIS : GameObject = GameObject.Find(“ball1”) ; // This is the object you turn on and off name it the same in Unity
objectTHIS.active = false ;
yield WaitForSeconds (Random.Range(0, 5)) ; // Throwing in a random generating for amount of time before it turns on again.
objectTHIS.active = true ;
}
}

The yield waits for an amount of time. The objectTHIS.active == false turns the object off, and true after the yield is done. The yield is using a random generator to mix it up but you can simplify this to .

yield WaitForSeconds(5); // wait five seconds

Make sure to make the object you want to be the ball1_TRIGGER object set to Is Trigger in the Collider component.

Additionally you could just build a short script that runs all this on and off alternating between on and off states and just wrap it in a function Update (). Create variables in the script for the time you want the object to turn on or off, and you can set it differently in Unity’s interface on various objects without having a mess of scripts for individual objects.

hope this helps.