- Home /
Game crashes on Loadlevel when called on a swipe event
Hi, On my game, whenever I call LoadLevel("mylevel") from a swipe event it crashes, the same LoadLevel("mylevel") works fine if I call it from a button click event.
I tested swipe with other calls (I show a dialog box when a swipe event is triggered) and it works fine.
Here is my swipe code:
void Update () {
if (Input.touchCount > 0){
for(int i = 0; i<Input.touchCount; i++)
{
Touch touch = Input.GetTouch(i);
switch (touch.phase)
{
case TouchPhase.Began :
// this is a new touch
isSwipe = true;
fingerStartTime = Time.time;
fingerStartPos = touch.position;
break;
case TouchPhase.Canceled :
// The touch is being canceled
isSwipe = false;
break;
case TouchPhase.Ended :
float gestureTime = Time.time - fingerStartTime;
float gestureDist = (touch.position - fingerStartPos).magnitude;
if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist){
Vector2 direction = touch.position - fingerStartPos;
Vector2 swipeType = Vector2.zero;
if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)){
// the swipe is horizontal:
swipeType = Vector2.right * Mathf.Sign(direction.x);
}else{
// the swipe is vertical:
swipeType = Vector2.up * Mathf.Sign(direction.y);
}
if(swipeType.x != 0.0f){
if(swipeType.x > 0.0f){
// MOVE RIGHT
//SwipeH();
MobileNativePopups.OpenAlertDialog(
"Swipe", "MOVE RIGHT",
"Cancel", () => { Debug.Log("Cancel was pressed"); });
}else{
// MOVE LEFT
MobileNativePopups.OpenAlertDialog(
"Swipe", "MOVE LEFT",
"Cancel", () => { Debug.Log("Cancel was pressed"); });
}
}
if(swipeType.y != 0.0f ){
if(swipeType.y > 0.0f){
// MOVE UP
MobileNativePopups.OpenAlertDialog(
"Swipe", "MOVE UP",
"Cancel", () => { Debug.Log("Cancel was pressed"); });
}else{
// MOVE DOWN
MobileNativePopups.OpenAlertDialog(
"Swipe", "MOVE DOWN",
"Cancel", () => { Debug.Log("Cancel was pressed"); });
}
}
}
break;
}
}
}
}
public void SwipeHandler(){
GameTimer.ResetGamePlay();
Application.Quit();
Application.LoadLevel ("startscreen");
}
public void SwipeHandler2(){
GameTimer.ResetGamePlay();
Application.Quit();
Application.LoadLevel ("Level_ag-01");
}
public void SwipeHandler3(){
GameTimer.ResetGamePlay();
Application.Quit();
Application.LoadLevel (Application.loadedLevel + 1);
}
void SwipeH(){
if (type == 0)
SwipeHandler ();
else if (type == 1) {
SwipeHandler2 ();
} else if (type == 2) {
SwipeHandler3();
}
}
Thank you for your help
Comment
Answer by Xarbrough · Jun 22, 2015 at 01:06 AM
Why do you call Application.Quit() but then load a level? As far as I'm concerned there is no level to load once you quit the application.
Your answer
![](https://koobas.hobune.stream/wayback/20220613201236im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Giant spike with level load causes crash with iphone 1 Answer
Crash on LoadLevel (Android Project) 1 Answer
iPad crashes on load level 2 Answers