Game Development Reference
In-Depth Information
The actions of the aliens' bullets, movements, and collision detection are basically
handled the same way we did for the player's bullets, with a script attached to the
bullet itself.
1. So create a new JavaScript in the Scripts folder, name it AlienShoot and
add the following code. You should now be used to the kind of actions ex-
pressed by the instructions of the script.
#pragma strict
//this var instantiates the bullet prefab
var itsBullet:Rigidbody;
function Start () {
}
function Update () {
}
//repeat firing check every 5 secs
InvokeRepeating("shouldFire",3,5);
function shouldFire()
{
//assign a random value between
0 and 1 to p
var p:float=Random.value;
//change p that alien fires
if(p>0.85)
{
doFire();
}
}
//this function instantiates an alien
bullet
Search WWH ::




Custom Search