unity Input.GetTouch

触摸交互案例

Input.GetTouch(0).deltaPosition;//获取触摸滑动增量
float num = Input.GetTouch(0).deltaPosition.y * 0.003f;//使用y值增量例子

其他
单指点击


using UnityEngine;
using System.Collections;
 
public class touchTest: MonoBehaviour {	
	void Update() {
		int i = 0;
		while (i < Input.touchCount) {
			if (Input.GetTouch(i).phase == TouchPhase.Began)//单指
			{
				++i;
			}			
		}
	}
}

拖拽

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TouchMoveTest : MonoBehaviour {
    static int count;//定义touchCount数    
    public Vector3 touchposition;//存储移动三维坐标值
 
	// Update is called once per frame
	void Update () {
        if (Input.touchCount > 0)
        {
            count += Input.touchCount;
        }
        if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)) //[color=Red]如果点击手指touch了  并且手指touch的状态为移动的[/color]
        {
            touchposition = Input.GetTouch(0).deltaPosition;  //[color=Red]获取手指touch最后一帧移动的xy轴距离[/color]
            //touchposition.x*0.01f, touchposition.y*0.01f//[color=Red]移动这个距离[/color]
        }
    }
    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 100, 30), "cishu:" + count.ToString());
        GUI.Label(new Rect(10, 50, 100, 30), touchposition.ToString());
    }
}

官方文档
相关api
在这里插入图片描述
在这里插入图片描述

posted @ 2022-06-22 18:04  哒哒哒~~~  阅读(273)  评论(0编辑  收藏  举报