Game Development Reference
In-Depth Information
//the swarm starts moving right
goRight=true;
//tweak the swarm speed according to
your tastes
vel=4;
//no collision when the game starts
bCollide=false;
}
3. Now we take care of having the swarm move. Movement is defined by a
function called moveEnemies() , which is called the first time in 0.5 seconds
after the game starts and then every 0.25 seconds by another instruction
called InvokeRepeating() . You can tweak these values if you like.
//this instruction calls the moveEnemies
functions at a
//given pace
InvokeRepeating("moveEnemies",0.5,0.25);
//we move the swarm left or right at
speed defined by vel
function moveEnemies()
{
if(goRight)
{
for(var myEnemy:GameObject in
enemyList)
{
if(myEnemy)
{
myEnemy.transform.Translate(Vector3(vel,0,0));
}
}
}
Search WWH ::




Custom Search