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;
}
}