Game Development Reference
In-Depth Information
//ship move right
transform.Translate(Vector3(shipSpeed,0,0));
}
//is the player pressing left button?
if(Input.GetKey("left") &&
transform.position.x>-25)
{
//ship move left
transform.Translate(Vector3(-shipSpeed,0,0));
}
//is player pressing the fire button
(spacebar)
if(Input.GetKeyDown("space")&&canShoot)
{
//create the bullet
Instantiate(myBullet,transform.position,
transform.rotation);
//player can't fire for a while
canShoot=false;
//play shooting audio fx
audio.Play();
}
}
7. The same process applies to the other three audio clips we chose for this
project. Add an
Audio Source
component to a prefab and drag the desired
audio file into its
Audio Source
slot.
8. For the aliens moving fx, we added the
Audio Source
component to the
SwarmManager
prefab. Since all aliens move as a whole, we can simply play
the audio once for each step from the
SwarmManager
prefab.
9. Add
audio.Play()
line into the
MoveEnemies()
function of the
Con-
trolSwarm
script. What follows is the updated
MoveEnemies()
function:
//we move the swarm left or right at
speed defined by vel