Hi
I am trying to rotate a cube by 90 horizontally or vertically depending upon user input. But its all confusing the cube’s rotation is behaving awkwardly.

Currently i am using this messed up code…
void Update ()
{
if (Direction != SwitchDirection.None) {
SwitchMap (Direction);
}
}
void OnGUI ()
{
if (GUI.Button (new Rect (Screen.width / 2, Screen.height - Screen.height / 10, 100, 100), "D")) {
Direction = SwitchDirection.Down;
}
if (GUI.Button (new Rect (Screen.width / 2, Screen.height / 40, 100, 100), "U")) {
Direction = SwitchDirection.Up;
}
if (GUI.Button (new Rect (0, Screen.height / 2, 100, 100), "L")) {
Direction = SwitchDirection.Left;
}
if (GUI.Button (new Rect (Screen.width - Screen.width / 10, Screen.height / 2, 100, 100), "R")) {
Direction = SwitchDirection.Right;
}
}
void SwitchMap (SwitchDirection switchDirection)
{
string direction = string.Empty;
float directionValue = 0;
switch (switchDirection) {
case SwitchDirection.Up:
direction = "x";
directionValue = transform.rotation.eulerAngles.x - 90;
break;
case SwitchDirection.Right:
direction = "z";
directionValue = transform.rotation.eulerAngles.z + 90;
break;
case SwitchDirection.Down:
direction = "x";
directionValue = transform.rotation.eulerAngles.x + 90;
break;
case SwitchDirection.Left:
direction = "z";
directionValue = transform.rotation.eulerAngles.z - 90;
break;
}
if (switchDirection != SwitchDirection.None) {
iTween.RotateTo (gameObject,
iTween.Hash (direction, directionValue,
"time", 0.5,
"easetype", iTween.EaseType.easeInBack
));
}
Direction = SwitchDirection.None;
}