重新加载场景时滑动输入失败

时间:2014-06-19 17:08:18

标签: c# unity3d

Application.LoadLevel("0"); 

在播放器失败并点击重试后立即重新加载场景。但是在像这样重新加载Level之后滑动输入失败可能是什么原因?

滑动代码

void Update()
{
    foreach (Touch t in Input.touches)
    {
        switch (t.phase)
        {
            case TouchPhase.Began:
                Initial = t.position;
                Swiped = false;
                break;
            case TouchPhase.Ended:
                Direction = t.position - Initial;
                if (Direction.magnitude > 100.0f)
                {
                    Direction = Direction.normalized;
                    Swiped = true;
                }
                break;
        }
        if (Swiped && count == 0)
        {

            if (Vector2.Dot(Direction, Vector2.up) > Mathf.Sqrt(0.5f))
            {
                // Up
                BroadcastMessage("swipedUp", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, -1 * Vector2.up) > Mathf.Sqrt(0.5f))
            {
                // Down
                BroadcastMessage("swipedDown", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, Vector2.right) > Mathf.Sqrt(0.5f))
            {
                // Right
                BroadcastMessage("swipedRight", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, -1 * Vector2.right) > Mathf.Sqrt(0.5f))
            {
                // Left
                BroadcastMessage("swipedLeft", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
}

上面的代码在我第一次开始玩游戏时效果很好,但是当我尝试重新加载相同的场景它失败了。游戏只有一个场景。我开始的方法

void Start()
{
    Swiped = false;
    paused = false;
    GameOver = false;
    count = 0;
}

1 个答案:

答案 0 :(得分:0)

检查代码中是否使用静态变量。调用Application.LoadLevel时,这些不会被重置(" 0");因为它们不是物体的一部分。