rotation

im pretty new at coding. it supposes to be moving in every angle. its a cube


using UnityEngine;
using System.Collections;

public class rotationTest : MonoBehaviour
{
IEnumerator RotateMe(Vector3 byAngles, float inTime)
{
var fromAngle = transform.rotation;
var toAngle = Quaternion.Euler(transform.eulerAngles + byAngles);
for (var t = 0f; t < 1; t += Time.deltaTime / inTime)
{
transform.rotation = Quaternion.Slerp(fromAngle, toAngle, t);
yield return null;
}
}
void Update()
{
if (Input.GetKeyDown(“d”))
{
StartCoroutine(RotateMe(Vector3.forward * 90, 0.8f));
}
if (Input.GetKeyDown(“a”))
{
StartCoroutine(RotateMe(Vector3.back * -90, 0.8f));
}

if (Input.GetKeyDown(“w”))
{
StartCoroutine(RotateMe(Vector3.right * 90, 0.8f));
}
if (Input.GetKeyDown(“s”))
{
StartCoroutine(RotateMe(Vector3.left * -90, 0.8f));
}
}
}


im new at coding…

Please edit your code into appropriate [.code] brackets

Indeed, it’s very difficult to read that code as is.

However, I do see that you’re running a whole bunch of coroutines that all operate on the same transform.rotation. What do you imagine would happen if you have several coroutines running at the same time?

Judging your code, you have achieved your goal, if you hit the keys, your cube will be moving (rotating) in every angle. But it does all direction at the same time.