Respawning Objects

Hello, I seem to be having some problems with my Character picking up objects…I want the character to walk over an object(ammobox) and have it disappear then reappear a few seconds later. I tried to use the instantiate method but the object doesn’t respawn and my character gains 200+ ammo every few seconds.The code I have tried to use is below. Any help would be great.

var ammo = 0;
var dead = false;
var gameobject : GameObject;

function Start () {

}

function Update () {

}

function OnControllerColliderHit(hit : ControllerColliderHit)
{
if (hit.collider.gameObject.tag == “ammo”)
{
Destroy(hit.collider.gameObject);
ammo += 10;
dead = true;
Debug.Log(ammo);
Respawn();
}

}

function Respawn()
{
if(dead)
{
Debug.Log(“Getthing here”);
yield WaitForSeconds(5);
Instantiate(gameobject,transform.position, transform.rotation);
dead = false;
}

}

1 Answer

1

I think your best bet would be to use the active attribute for the gameobject you want to disappear. something like

If(player touches gameobject)
		{
			//disactivate renderer
			//disactivate script that adds ammo
			//use a timer to count so many seconds then turn them back on.
		}

sorry this is extremely basic but I’m at work right now and don’t have code in front of me :stuck_out_tongue: