Cube that rotates on swipe

Hi,
i am new to Unity and I stuck on 2 problems.

I am making cube for android mobile phones.For now I managed to make cube with 6 planes, each in different color. (because i didn’t figure how to make if with simple 3D cube if possible) I connect them all so they are now rotating like single cube.

My problems are :
-how to make cube to rotate just for 90 degrees in direction where user swipe. And I need rotation to be visible,and not just to front plane change color ( now on swipe my front plane just change color)
I tried using rotations and time but cube just swipe too little or pass 90 degrees rotation.

-Second problem is how to put arrows on front plane.(4 arrows pointing in different directions and dinamically choose directions after each rotation) I tried to put transparent plane in front of cube but couldn’t figure out how to position arrows on it. Is it good approach or you guys done it on different way.

Could you help me with explained solution or point me where to look?

You could use unity gui for the arrows. As for the rotations, maybe post the code you have so far ( please use code tags ). But I would just Lerp the EulerAngles after each swipe.

using UnityEngine;
using System.Collections;

public class SwipeDetector : MonoBehaviour
{


    public float minSwipeDistY;
    public float minSwipeDistX;

    // Use this for initialization
    void Start()
    {

    }

    float f_startX = 0.0f;
    float f_startY = 0.0f;
    float f_endX = 0.0f;
    float f_endY = 0.0f;

    float f_difX = 0.0f;
    float f_difY = 0.0f;

    bool canRotate;

    void rotateX(bool right)
    {
        int y = 0;
        if (right)
        {
            y = 90;
        }
        else
        {
            y = -90;
        }
        var oldRotation = transform.rotation;

        transform.Rotate(0, y, 0);
        var newRotation = transform.rotation;

        for (float t = 0.0f; t <= 1.0; t += Time.deltaTime)
        {
            transform.rotation = Quaternion.Slerp(oldRotation, newRotation, t);
            // yield return 1;
        }

        transform.rotation = newRotation; // To make it come out at exactly 90 degrees
    }

    void rotateY(bool up)
    {
        int x = 0;
        if (up)
        {
            x = 90;
        }
        else
        {
            x = -90;
        }
        var oldRotation = transform.rotation;
        transform.Rotate(x, 0, 0);
        var newRotation = transform.rotation;

        for (float t = 0.0f; t <= 1.0; t += Time.deltaTime)
        {
            transform.rotation = Quaternion.Slerp(oldRotation, newRotation, t);
            // yield return 1;
        }

        transform.rotation = newRotation; // To make it come out at exactly 90 degrees
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            f_startX = Input.GetAxis("Mouse X");
            f_startY = Input.GetAxis("Mouse Y");


        }
        else if (Input.GetMouseButtonUp(0))
        {

            f_endX = Input.GetAxis("Mouse X");
            f_endY = Input.GetAxis("Mouse Y");

            f_difX = Mathf.Abs(f_endX - f_startX);
            f_difY = Mathf.Abs(f_endY - f_startY);



            //horizontal swipe
            if ((f_difY - f_difX) > minSwipeDistY)
            {
                if (f_endX > f_startX)
                {//right
                    Debug.Log("down scroll ");
                    rotateY(false);
                }
                else
                {//left
                    Debug.Log("up scroll");
                    rotateY(true);
                }

            }
            //vertical swipe
            else if ((f_difX - f_difY) > minSwipeDistX)
            {
                if (f_endY > f_startY)
                {//up
                    Debug.Log("right scroll ");
                    rotateX(true);
                }
                else
                {//down
                    Debug.Log("left scroll");
                    rotateX(false);
                }
            }

        }
    }

}

First I only play game in landscape mode.

I figure now that even rotation doesn’t work as it supposed to.
Cube rotate unexpectedly on swipe, sometimes it rotates good and sometimes opposite. I couldn’t found right pattern calling “rotateX” and “rotateY”.
I even found snippet code for smooth rotate and rewrite it for X and Y orientations but it doesn’t animate rotation at all.

  1. What do you mean by unity gui??

Anyone? At least some hint or anything.

Your rotate x and y functions are named wrong. Unity’s 2D Graphics library. Creating a canvas with render set to world space and placing the sprites either side of the cube to show directions.

Or just 2D arrows set to Screen Space → Overlay

Naming is on purpose because when I put mobile in andscape mode left swipe makes up movement, up swipe makes right etc…