标签:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DoHasRotateTheSphere : MonoBehaviour {
    public GameObject Obj;
    private int curFrame = 0;
    private bool isOnClick = false;
    private float rotationValue = 5f;
    private Vector3 touchPos = Vector3.one;
    //public Button Btn;
    // Use this for initialization
    void Start()
    {
        
        Obj = gameObject;
        StartCoroutine(RotateAuth());
}
    void Update()
    {
        TouchRotate();
        
    }
  
    void OnClick()
    {
        Debug.Log("值" + Obj.transform.localEulerAngles);
        Obj.transform.localEulerAngles = new Vector3(0, 0, GetrotationValue(Obj.transform.localEulerAngles.z));
    }
   
    //触摸旋转
    void TouchRotate()
    {
        if (Input.touchCount == 1)
        {
            if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                touchPos = Input.GetTouch(0).deltaPosition;
                Obj.transform.Rotate(0, 0, -touchPos.x * 3, Space.Self);
            }
        }
        if (Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            OnClick();
            StartCoroutine(RotateAuth());
        }
    }
    //传入旋转的z值
    private float GetrotationValue(float zValue)
    {
        float curValue = 0f;
        float value = 0f;
        if (zValue > 270)
        {
            curValue = zValue - 270;
            value = 270;
        }
        else if (zValue > 180)
        {
            curValue = zValue - 180;
            value = 180;
        }
        else if (zValue > 90)
        {
            curValue = zValue - 90;
            value = 90;
        }
        else
        {
            curValue = zValue;
            value = 0;
        }
        curValue = value + (GetValue(curValue));
        return curValue;
    }
    private float GetValue(float value)
    {
        float curValue = 0;
        if (value > 45)
        {
            curValue = 90;
        }
        else
        {
            curValue = 0;
        }
        return curValue;
    }
    IEnumerator  RotateAuth()
    {
        yield return new WaitForSe                  conds(3f);
        Obj.transform.Rotate(0, 0, 0.05f);
    }
}
标签:
原文地址:http://www.cnblogs.com/ZeroMurder/p/5654299.html