i am trying to rotate object 180 degrees on every input smoothly, here in my code object rotating 0 to 180 degrees fine on first input but its rotating 180 to 0 degrees on second input not 180 to 360 degrees
public float speed = 0.9f;
private Quaternion to;
private void Start()
{
to = transform.rotation;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
RotateTwo();
}
if (Input.GetKeyDown(KeyCode.D))
{
RotateOne();
}
transform.rotation = Quaternion.Lerp(transform.rotation, to, speed * Time.deltaTime);
}
void RotateOne()
{
to *= Quaternion.Euler(0, 0, 180);
}
void RotateTwo()
{
to *= Quaternion.Euler(0, 0, -180);
}