-1

我是unityscript和unity的新手,我试图在触摸移动位置为触摸右侧+100时触发动画,所以我也尝试过+500和+1000,似乎动画正在播放触摸在屏幕上超过 100,500 或 1000,而不是 touch.began 位置 +(数量),感谢您的帮助,感谢您的时间,因为我是 unityscript 的新手

#pragma strict
var distance : float = 10;
var joystick : GameObject;
private var first : boolean = false;
function Start () {

}

function Update () {
transform.eulerAngles = Vector3(0,Camera.main.transform.eulerAngles.y + 180,0);

var v3Pos : Vector3;
if (Input.touchCount > 0 && 
          Input.GetTouch(0).phase == TouchPhase.Began) {

            // Get movement of the finger since last frame
            var touchDeltaPosition:Vector2 = Input.GetTouch(0).position;
            if(!first){
            var touchdet : Vector2 = touchDeltaPosition;
            first = true;
            }

            // Move object across XY plane
            v3Pos = Vector3(touchDeltaPosition.x, touchDeltaPosition.y, distance);
         transform.position = Camera.main.ScreenToWorldPoint(v3Pos);
        }


 if (Input.touchCount > 0 && 
          Input.GetTouch(0).phase == TouchPhase.Moved) {

            // Get movement of the finger since last frame
            var touchAlphaPosition:Vector2 = Input.GetTouch(0).position;

            // Move object across XY plane
            v3Pos = Vector3(touchAlphaPosition.x, touchAlphaPosition.y, distance);
         transform.position = Camera.main.ScreenToWorldPoint(v3Pos);
        }

        if (Input.touchCount > 0 && 
          (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled )) {

            // Get movement of the finger since last frame
            var touchBetaPosition:Vector2 = Input.GetTouch(0).position;
            first = false;
            // Move object across XY plane
            v3Pos = Vector3(touchBetaPosition.x, 600, distance);
         transform.position = Camera.main.ScreenToWorldPoint(v3Pos);
        }

        if(first)
        {
        if(touchAlphaPosition.x > touchdet.x + 100)
        {
        animation.Play("Right");
        }
        }

}
4

1 回答 1

1

变量 touchDet 在函数 Update 中声明和初始化,因此函数调用之间不会保留该值。除了触发 TouchPhase.Began 事件的迭代之外,touchDet 将始终等于 Vector2.zero。

于 2013-06-14T02:22:05.570 回答