码迷,mamicode.com
首页 > 其他好文 > 详细

11111

时间:2016-07-08 19:53:16      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

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);
}

}

11111

标签:

原文地址:http://www.cnblogs.com/ZeroMurder/p/5654299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!