Continuous rotation on key press?
using UnityEngine; using System.Collections;
public class Rotation : MonoBehaviour {
// Use this for initialization
void Start()
{
}
// Update is called once per frame
public float turnSpeed = 50f;
void Update()
{
if (Input.GetKey(KeyCode.A))
transform.Rotate(Vector3.up * turnSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Rotate(Vector3.up * -turnSpeed * Time.deltaTime);
}
}
this is my code i need help on how to make an infinite rotation but it will change its rotation when a specific key is pressed going left or going right
Comment
Best Answer
Answer by mikelortega · Dec 14, 2015 at 01:29 PM
What do you mean with infinite? Keep rotating even if a key is not pressed? Then, try this...
public float turnSpeed = 50.0f;
void Update()
{
transform.Rotate(Vector3.up * turnSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
turnSpeed = 50.0f
if (Input.GetKey(KeyCode.D))
turnSpeed = -50.0f
}