How do I go back to the normal walking speed?
So now that I have done the rotation, What I am attempting right now is that whenever the space key is pressed the players speed will stop and when let go it would revert back to the normal walking speed.
public class Rotate : MonoBehaviour { public float speed = 10f; void Start() {
}
void Update()
{
var rotation = new Vector3(0f, 0f, 1f);
if (Input.GetKey(KeyCode.Space))
{
speed = 0;
}
if((transform.rotation.z >= Quaternion.Euler(0,0,65).z) || (transform.rotation.z <= Quaternion.Euler(0, 0, -65).z))
{
speed = -speed;
}
transform.Rotate(rotation * speed * Time.deltaTime, Space.Self);
}
}
Comment