物体随着鼠标旋转(触屏)

来源:互联网 发布:蓝天Windows装机 编辑:程序博客网 时间:2024/05/06 11:25


        if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved && move == true)
        {
            float xm = transform.position.x;
            float ym = transform.position.y;
            float x = Input.GetTouch(0).deltaPosition.x;
            float y = Input.GetTouch(0).deltaPosition.y;   //最关键的是在这里,这里是deltaPositon不是position


            if (xm > 2f)
            {
                xm = 2;
            }
            if (ym > 2)
            {
                ym = 2;
            }
            if (xm < -2)
            {
                xm = -2;
            }
            if (ym < -2)
            {
                ym = -2;
            }
       
    transform.position = new Vector3(xm, ym, 0);这里是限制物体的移动区域
            transform.Translate(Vector3.up * y / 100, Space.World);
        transform.Translate(Vector3.left * x / 100, Space.World);
        }

0 0
原创粉丝点击