using UnityEngine;
using System.Collections;

public class UIRotate : MonoBehaviour
{

    public bool mExcute;
    public float speed;
    public bool left;
    public bool rotateX;
    public bool rotateY;
    Vector3 baseDir;
    float x;
    float y;
    float z;
    void Start()
    {
        baseDir = transform.localEulerAngles;
    }

    // Update is called once per frame
    void Update()
    {
        if (mExcute)
        {
            if (rotateX)
            {
                if (left)
                {
                    x += Time.deltaTime * speed;
                }
                else
                {
                    x -= Time.deltaTime * speed;
                }
            }
            else if (rotateY)
            {
                if (left)
                {
                    y += Time.deltaTime * speed;
                }
                else
                {
                    y -= Time.deltaTime * speed;
                }
            }
            else
            {
                if (left)
                {
                    z += Time.deltaTime * speed;
                }
                else
                {
                    z -= Time.deltaTime * speed;
                }
            }
            SetRotate();
        }
    }

    void SetRotate()
    {
        if (rotateX)
        {
            transform.localEulerAngles = new Vector3(x, baseDir.y, baseDir.z);
        }
        else if (rotateY)
        {
            transform.localEulerAngles = new Vector3(baseDir.x, y, baseDir.z);
        }
        else
        {
            transform.localEulerAngles = new Vector3(baseDir.x, baseDir.y, z);
        }
    }
}