So I’ve got a ship that moves up and down when you tilt the device, but when the lives reach zero, I want the ship to stop. I have an if statement for when lives equal zero for the speed to then reach zero and an overlay to occur. The overlay works but the ship still moves up and down. Can anyone help with my problem as I honestly have no clue =( Code below (but it might not conform to the standard format at the mo!)
public class PlayerScript : MonoBehaviour {
// Use this for initialization
public float speed = 10.0f;
public int lives = 5;
void Start(){
speed = 10f;
}
// Update is called once per frame
void Update () {
Vector3 dir = Vector3.zero;
dir.x = 0;
dir.z = 0;
dir.y = (Input.acceleration.y);
if (dir.sqrMagnitude > 1)
dir.Normalize ();
dir *= Time.deltaTime;
if (lives == 0) {
transform.parent.gameObject.AddComponent<GameOver> ();
speed = 0;
}
if (lives >= 1) {
transform.Translate (dir * speed);
}
}