touch------一个手指旋转,两个手指移动

using UnityEngine;
using System.Collections;

public class TouchMoveDir : MonoBehaviour {
public GameObject TextPrefab;
private GameObject tempText;

private Vector3 touchPosition; //存储一个vector3值
public float touchSpeed = 0.1f; //设定一个移动速度
public float rotateSpeed = 50.0f;
void FixedUpdate()
{
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
//判断是否是单点触摸
if (Input.touchCount == 1)
{//判断是是类型为移动触摸
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{ //根据触摸点计算x和y的位置,然后重置位置
//target.transform.Translate(Vector3.forward * Time.deltaTime * 5);
//target.transform.LookAt(target.position);
gameObject.transform.Rotate(0, touchPosition.x * rotateSpeed, 0);
// ResetPos();
}
}
}
//如果触摸大于0,并且移动时
if (Input.touchCount == 2)
{
if (Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved)
{

//获取手指最后一帧移动的xy轴距离
touchPosition = Input.GetTouch(0).deltaPosition;
//让物体移动这个距离
gameObject.transform.Translate(touchPosition.x * touchSpeed, 0, 0);
TextPrefab = GameObject.Find("Canvas");
tempText = Instantiate(Resources.Load("Text") as GameObject);
tempText.transform.parent = TextPrefab.transform;
tempText.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 130);
//ResetPos();
}
}
}
// void ResetPos() {
//gameObject.transform.Rotate(26.6f, 104.4f, 987.0065f);
//gameObject.transform.Translate(26.6f, 104.4f, 987.0065f);

//}
void OnGUI()
{
GUI.Label(new Rect(50, 100, 200, 20), "x pos is" + touchPosition.x + "float");
// GUI.Label(new Rect(50, 120, 200, 20), "y pos is" + touchPosition.y + "float");

}

}

posted @ 2016-06-30 09:58  Fei非非  阅读(342)  评论(0编辑  收藏  举报