Game Development Reference
In-Depth Information
Destroy(gameObject);
Destroy(other.gameObject);
//once the bullet is destroyed,
allow the player
//to shoot again
ControlShip.canShoot=true;
}
//the bullet collides with barriers:
destroy bullet and
//a piece of the barrier
if(other.gameObject.tag=="BarrierBrick"){
Destroy(gameObject);
Destroy(other.gameObject);
//once the bullet is destroyed,
allow the player
//to shoot again
ControlShip.canShoot=true;
}
}
5. Save the script and drag it onto the PLBullet Prefab.
If you test the project now, you should have the player's ship firing and the bullet
move up, until it collides with an alien or gets out of the top boundary of the screen.
You should also notice that you won't be able to shoot again until the last bullet is
destroyed. In the Update() function you can also tweak the speed of the bullet as
it goes up and the height it gets destroyed at, if it doesn't collide with anything.
Having the aliens shoot at the player's ship can be achieved in many different ways.
For the sake of this tutorial we will show a very straightforward method, simply based
on probabilities. We basically call a function every five seconds and with each call,
we set a probability that each alien in the swarm fires a bullet against the player's
ship.
Search WWH ::




Custom Search