Unity 手机平板触屏,触摸方法的使用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TouchTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //开启多点触摸
        Input.multiTouchEnabled = true;
    }

    // Update is called once per frame
    void Update()
    {
        //判断单点触摸
        if (Input.touchCount == 1){
            //触摸对象
            Touch touch = Input.touches[0];
            //触摸位置
            Debug.Log(touch.position);
            //触摸阶段
            switch(touch.phase){
                //开始触摸
                case TouchPhase.Began:
                    break;
                //移动
                case TouchPhase.Moved:
                    break;
                //静止
                case TouchPhase.Stationary:
                    break;
                //结束
                case TouchPhase.Ended:
                    break;
                //因其他事件打断,取消
                case TouchPhase.Canceled:
                    break;
            }
        }

        //判断多点触摸
        if (Input.touchCount == 2){
            Touch touch1 = Input.touches[0];
            Touch touch2 = Input.touches[1];
        }
    }
}

猜你喜欢

转载自blog.csdn.net/ssl267422/article/details/128378171