I want my cube to turn left and right while moving my cube ahead my code for turning left in every state of cube , code is as follows
using UnityEngine;
using System.Collections;
void Update () {
transform.position += transform.forward * speed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
if (transform.rotation.y == 0)
{
transform.rotation = Quaternion.Euler(0, -90 , 0);
}
else if (transform.rotation.y == -90)
{
transform.rotation = Quaternion.Euler(0, -180 , 0);
}
else if (transform.rotation.y == -180)
{
transform.rotation = Quaternion.Euler(0, -270 , 0);
}
transform.Rotate(Vector3.left * Time.deltaTime * speed );
}
}
it works till for the first left turn then when again i press left arrow key nothing happens
↧