How so I stop a function from running?
I have a script that calls a custom function when the player enters a trigger but I can’t get it to stop when the player leaves the trigger?
#pragma strict
var boulder01 : GameObject;
var BoulderSpawn01 : Transform;
function OnTriggerEnter ()
{
SpawnBoulder(); //Call new function
}
function SpawnBoulder ()
{
for (var x = 1; x < 2; x++) //Set max limit of spawns
{
yield WaitForSeconds (5);
Instantiate(boulder01, BoulderSpawn01.transform.position, BoulderSpawn01.transform.rotation);
}
}
Any suggestions?