Unity - 触摸

Test_03 —“TouchTest”

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;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        
        // 判断是否为多点触摸
        if (Input.touchCount == 2)
        {
            // 获取触摸对象
            Touch touch  = Input.touches[0];
            Touch touch1 = Input.touches[1];
        }
    }
}

你可能感兴趣的:(unity,unity)