I’m doing a transform rotation if you hit the left or right arrow keys.
building mainly a turret the player can control, I can get it to rotate per left arrow hit, but for that’s not gonna work well at all and i want to do a while left arrow is down but that locks the game up.
This is what I have so far.
public class turretbehave : MonoBehaviour {
//public Transform Shot; to be used later
public float rotateRate = Mathf.PI /6; // 30 degrees per second
public GameObject turret;
private bool spin = false;
// Use this for initialization
void Start () {
turret = GameObject.Find("Player");
spin = false;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
spin = true;
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
spin = true;
}
while (spin == true Input.GetKeyDown(KeyCode.LeftArrow))
{
turret.transform.RotateAround(Vector3.up, (rotateRate * Time.deltaTime) * -1f);
if (Input.GetKeyUp(KeyCode.LeftArrow))
{
spin = false;
}
}
while (spin == true Input.GetKeyDown(KeyCode.RightArrow))
{
turret.transform.RotateAround(Vector3.up, rotateRate * Time.deltaTime);
if (Input.GetKeyUp(KeyCode.RightArrow))
{
spin = false;
}
}
}
}
can someone give me a hand with getting my turret up and spinning in circles?
thanks.