I am making a game using javascript. I was wondering how to make a game object respawn after a certain amount of time. the idea is the character collects the object and then after about 20 seconds the object respawns at the same point. The character can then collect the object again.
My original script is the following: private var timeSinceLastCollision = 0;
function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag == "PowerUp(smaller)" && timeSinceLastCollision <= 0)
{
Destroy(hit.gameObject);
transform.localScale = Vector3(transform.localScale.x * .5, transform.localScale.y * .5, transform.localScale.z * .5);
timeSinceLastCollision = 5;
//Wait at least 5 seconds between collisions
}
timeSinceLastCollision -= Time.deltaTime;
}
so where do I put the script you wrote and what do I put in the spot where you wrote (collecteditem)