- Home /
How to undo cancel Invoke
So I use invoke repeating until a certain number is reached and then cancel the invoke. But is tere any syntax in JS to "reinvoke repeating" FROM A SEPARATE SCRIPT? Thank you for your time and any helpful pointers, ideas, and tutorials would be very helpful. Note this is for spawning zombies(just experimental, there are probably better ways to code this). Here is my code so far...
var SpawnObject : GameObject;
var player : Transform;
private var SpawnStartDelay : float = 0;
var SpawnRate : float = 1.0;
private var amountOfE : float = 0;
var maxAmount : float = 10;
var distance = 15;
var playerCloseEnough = false;
var delay:float;
function Start()
{
AttackDelay();
}
function AttackDelay()
{
var timePointer:float=Time.time+delay;
for(;timePointer>Time.time;)
yield;
InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate);
}
// Spawn the SpawnObject
function Spawn()
{
amountOfE++;
Instantiate(SpawnObject, transform.position + (transform.forward * 5.0f), transform.rotation);
}
function Update()
{
if(amountOfE == maxAmount)
{
CancelInvoke("Spawn");
amountOfE = 0;
}
else{}
}
would you not put the if(amountOfE == $$anonymous$$axAmount) into the attack delay to stop it from invoking its self
function AttackDelay()
{
var timePointer:float=Time.time+delay;
for(;timePointer>Time.time;)
yield;
if(amountOfE != maxAmount)
{
InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate);
}
}
sorry i miss understood the question.
attack delay is public so if you use
objectThatHasTheScript.GetComponent.<SpawnObject>().AttackDelay();
wich will call the function i do not know what the name of the object that the scripted is attached to is called so i used objectThatHasTheScript
Answer by Runalotski · Aug 18, 2015 at 02:16 PM
Attack delay is public so if you use
objectThatHasTheScript.GetComponent.<SpawnObject>().AttackDelay();
wich will call the function i do not know what the name of the object that the scripted is attached to is called so i used objectThatHasTheScript
Your answer
Follow this Question
Related Questions
How do I spawn enemies based on a timer? 1 Answer
How to add a peaking system? 1 Answer
Making an Array of Spawnpoints... 1 Answer
Spawning enemies in waves 1 Answer
syntax for 'using' in javascript 1 Answer