Game Development Reference
In-Depth Information
function Update () {
//is the player pressing right button and
the ship can move
//right
//tweak the x reference value as needed
if(Input.GetKey("right") &&
transform.position.x<25)
{
//ship move right
transform.Translate(Vector3(1,0,0));
}
//is the player pressing left button and the
ship can move left
//tweak the x reference value as needed
if(Input.GetKey("left") &&
transform.position.x>-25)
{
//ship move left
transform.Translate(Vector3(-1,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;
}
}
Search WWH ::




Custom Search