So, I have a 2d sprite that needs to move forward when the vertical axis is greater then 0. This works fine. I also made it so that the sprite cannot rotate unless moving forward. But now, I want to have the sprite change speed when shift or control is pressed. But here’s the problem. When I press shift everything works great, the sprite goes double the speed and can rotate. But when I press control, it cuts the speed in half, like it is supposed to, but I cannot rotate what so ever. Note it is all in C#.
using UnityEngine;
using System.Collections;
public class Car : MonoBehaviour {
public float speed;
float actualSpeed;
public float rotationSpeed;
float actualRotationSpeed;
void Start () {
}
void Update () {
if (Input.GetKey (KeyCode.RightShift)) {
actualSpeed = speed * 2;
} else if (Input.GetKey (KeyCode.LeftShift)) {
actualSpeed = speed * 2;
} else if (Input.GetKey (KeyCode.RightControl)) {
actualSpeed = speed / 2;
} else if (Input.GetKey (KeyCode.LeftControl)) {
actualSpeed = speed / 2;
} else {
actualSpeed = speed;
}
if (Input.GetAxis ("Vertical") > 0) {
actualRotationSpeed = rotationSpeed;
}
if (Input.GetAxis ("Vertical") < 0) {
actualRotationSpeed = -rotationSpeed;
}
if (Input.GetAxis ("Vertical") == 0) {
actualRotationSpeed = 0;
}
}
void FixedUpdate(){
transform.Translate (Vector3.up * Input.GetAxis("Vertical") * actualSpeed);
transform.Rotate (new Vector3(0, 0, -1), Input.GetAxis("Horizontal") * actualRotationSpeed);
}
}