Hello, I’m trying to get weapons in my game to respawn after x ammount of seconds. This is the current script that works great other then… if the item is alredy spawned it’ll keep spawning the item after each 10 seconds. So If you wait 20 seconds you have two of the same items… How can I get / change the script so that it detects if the item is still there or if the item was picked up by a player it’ll start the timer to respawn then activate the timer when a player picks it back up.
Here is the current script:
var cube : GameObject;
var spawn_position;
var timer = 0.0;
function spawn_cube ()
{
spawn_position = Vector3(1,1,1);
var temp_spawn_cube = Instantiate (cube, spawn_position, Quaternion.identity);
}
function Start () {
}
function Update () {
timer += Time.deltaTime;
if(timer > 20)
{
spawn_cube();
timer = 0.0;
}
}
IE: Player picks it up, timer starts, item spawns and waits to be picked up before timer and spawner start again.