- Home /
Application.LoadLevel not working on iOS
I have created a script that handles all interface buttons.
This script handles navigation to new scenes and button press states etc.
When I test, with Unity Remote 3, I get no issues, but obviously, that runs on my desktop. When I try to build for iOS, tapping the button will not switch scene.
Here is my Update()
code:
if(navigate){
if(Time.time > delayedTime){
Application.LoadLevel(targetSceneOrAction);
}
}
I have a fade out script on the camera, and this part just checks to see if the screen has fully faded (via a delayed time) and if it has, navigate to the next scene.
The targetSceneOrAction
variable is a String
which is public (allowing me to set it in the inspector for each button on an individual basis).
A Debug.Log
of targetSceneOrAction
reveals the correct string, and as mentioned, it works fine whilst testing within Unity.
On button press, the variable navigate
is set and then the above function is accessible from the Update()
Are there any restrictions I need to be aware of when building for iOS.
At the moment, my app won't navigate from the homescreen and it's hugely inconvenient.
All in all, this script is one of the most simple processes in my app, there's nothing hugely complex, so it's kinda alarming that it's not working...
Thanks in advance for any help you can offer!
UPDATE
Application.LoadLevel(1);
With an indexed integer seems to work, though the very nature of the script is that anything can be passed to it to dynamically manage the scene switching. Is there any way I can do this through strings?
REQUESTED
if (Input.touchCount>0)
for(var t in Input.touches){
if(t.phase == TouchPhase.Began && guiTexture.HitTest(t.position))
ButtonTapped();
else if(t.phase == TouchPhase.Ended && guiTexture.HitTest(t.position))
ResetButton();
}
else
ResetButton();
My input detection works fine, both on build in iOS and in Unity Remote 3. ButtonTapped()
switches the guitexture to a button down style state, and reset button switches it back.
It also wouldn't be a mis-spell because it works in Unity Remote
Answer by venkspower · May 23, 2012 at 10:11 AM
You should give it as Application.LoadLevel("targetSceneOrAction");
or give it as Application.LoadLevel(1);
and set the scene number to '1' in the build settings of Unity.
targetSceneOrAction is a variable, if I put it into quotemarks it'll take it as a literal. I need something where I can have a dynamic variable in here. It does work with 1
but it's not dynamic.
I had to use an integer variable in the end. I created a public variable to handle it.
Answer by Bunny83 · May 23, 2012 at 10:46 AM
How do you detect your "tap" ? Keep in mind that
OnMouseEnter
OnMouseOver
OnMouseExit
OnMouseDown
OnMouseUp
OnMouseUpAsButton
OnMouseDrag
won't work on iPhone.
On other platforms Unity automatically performs a Raycast each frame to fire those events. For performance reasons this has been disabled on iPhone / mobile.
It would help to see your actual input detection...
If the Loadlevel is executed the only reason to fail would be that the scene isn't part of your build (note if you misspelled the name it's the same reason ;))
Your answer
![](https://koobas.hobune.stream/wayback/20220613071828im_/https://answers.unity.com/themes/thub/images/avi.jpg)