重新加载场景时,滑动输入失败 [英] Swipe Input fails when Reloading Scene

查看:127
本文介绍了重新加载场景时,滑动输入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Application.LoadLevel("0"); 

在播放器失败并单击重试后立即重新加载场景.但是这样重新加载了关卡后,滑动输入失败了.这可能是什么原因?

to Reload the scene as soon the player fails and clicks on retry. But after the Level has been reloaded like this the swipe Input fails What can be the reason for this?

刷卡代码

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);
            }
        }
    }
}

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

The above Code Works great when I first start playing the game, but when I try to reload the same scene It fails.The Game has only one Scene.My Start Method

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

推荐答案

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

Check if you are using static variables in your code. These will not be reset when you call Application.LoadLevel("0"); because they are not part of the objects.

这篇关于重新加载场景时,滑动输入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆