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;
}
}
17. The script basically controls that the bullet moves up once fired. In the Up-
date() function we also check if a collision occurs and perform the desired
action when this happens.
18. You will also notice that we are using Tag to check what the bullet collides
with.
19. Tags are another very useful feature offered by Unity that allows us to give an
identification name to game objects to be used to check collisions and other
events. We will explain how to use tags as we go on with this tutorial.
20. It may be necessary to adjust the bullet speed, which can be done by modi-
fying the following line in the Update() function:
//move bullet up once created
transform.Translate(Vector3(0,2,0));
21. The Y threshold to destroy the bullet once it goes beyond the upper screen
limit could require to be changed too, by editing the following line in the Up-
date() function:
//Y=100 defines upper screen limit
if(transform.position.y>100)
22. Now, everything should be ready to test the ship controls. Launch the applic-
ation and check that the ship actually moves left and right with the arrow keys
and fires when you press the spacebar.
Feel free to tweak its movement speed values according to your tastes.
Search WWH ::




Custom Search