Unity 触摸事件的运用

1.

// Update is called once per frame
    void Update()
    {

        //Debug.Log("Direction Vector: " + GetDirectionVector());

        if (Input.touchCount > 0)
        {
            //获取第一次触摸事件,触摸事件存放在一个数组里
            Touch touch = Input.GetTouch(0);
            //将触摸点的坐标转化为unity 世界坐标
            Vector3 touch_pos = new Vector3(touch.position.x, touch.position.y, 0);


            //手指开始触摸屏幕
            if (touch.phase == TouchPhase.Began)
            {

            }

            //如果手指停留在屏幕或者在屏幕上移动
            if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
            {
                
            }

            //结束触碰屏幕
            if (touch.phase == TouchPhase.Ended)
            {
               
            }

        }

    }

猜你喜欢

转载自blog.csdn.net/weixin_45203752/article/details/123641045