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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…