Hello i have a script where a stone is sopose to spawn, and after u have walked up to it and picked it up, it will start a timer to then instantiate a new stone. But the problem is, when i pick up the first stone, then on the secound try, when an other stone has spawned, if i rightclick to pick it up, it gives me 200 stones? Did i do something wrong in the script?
Thanks ~carlqwe
Script:
#pragma strict
var StonePrefab : Transform;
private var canSpawnStone : boolean = false;
function Start ()
{
SpawnStones();
}
function Update ()
{
if(canSpawnStone == true)
{
SpawnStonesWait();
}
}
function SpawnStonesWait ()
{
yield WaitForSeconds(5);
SpawnStones();
}
function SpawnStones ()
{
Instantiate(StonePrefab, transform.position, transform.rotation);
canSpawnStone = false;
}
function OnTriggerStay (col : Collider)
{
if(col.tag == "Player" && Input.GetMouseButtonDown(1))
{
canSpawnStone = true;
}
}