- Home /
Question by
moonLite · Apr 13, 2012 at 07:37 AM ·
spawninvokerepeating
How do I add a timer /wait time & limiter for Spawning?
Hi Guys,
var enemySlot: GameObject;
var spawn1 : GameObject;
var spawn2 : GameObject;
var spawnTime = 70.0;
var Xenemies : int; // to define how many enemies i wish to clone in each
//spawn period
function Update ()
{
InvokeRepeating("spawn", .01, spawnTime);
}
function spawn()
{
var time : int = Time.realtimeSinceStartup * 1000;
if((time & 0x01) == 0) //Checking if the time millisecond count is an even number(To make it come out of random side)
{
Instantiate(enemySlot, spawn1.transform.position, Quaternion.identity);
Debug.Log("spawn1 enemy created");
//yield WaitForSeconds(3);
}
else
{
Instantiate(enemySlot, spawn2.transform.position, Quaternion.identity);
Debug.Log("spawn2 enemy created");
}
}
I tried using the InvokeRepeating, but it still clone too many.
1) How do i add a timer or wait time to the code, so it will like every 3 sec then it will clone X enemies.
2) Where & how should i put my Xenemies in the code, so i can define like each Spawn execution, clone X number of enemies.
3) and how should I actually use the InvokeRepeating in this case to help my game?
Thanks in advance!
Comment
Should this act as waves - When first wave is either destroyed or off-screen the next wave comes? Don't forget you have for-loops and possibility to yield within them.
Your answer