Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

Swipe Code

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
168 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...