September 2010
Beginner
384 pages
8h 49m
English
Let's add a few lines of code to the HeroShip Script to make the bullet fire when you click on the mouse button, because shooting is cool.
function Update ()
{
var halfW:float = Screen.width/2;
transform.position.x = (Input.mousePosition.x )/20;
if(Input.GetMouseButtonDown(0)){
Instantiate(bullet, transform.position + new Vector3(0,3,0), Quaternion.identity);
}
}
Let's review.
if(Input.GetMouseButtonDown(0)){
This line returns true if the left mouse button (which has an ID of 0) has been pushed down within this Update cycle.
Instantiate(bullet, transform.position+new Vector3(0,3,0), Quaternion.identity);
We've used the Instantiate command before this time, we're creating a new BulletPrefab instance in the same position as ...
Read now
Unlock full access