Hi, am doing the project RollBall and I want make my player who increase speed by 10.0f every time I press ‘o’ but it wont script:
public class PlayerMovements : MonoBehaviour {
public float speed;
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movements = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movements * speed * Time.deltaTime);
shift ();
}
public void shift (){
if (Input.GetKeyDown (KeyCode.O)) {
speed = speed + 10.0f;
} else {
speed = 400.0f;
}
}
}