- Home /
touch to loadlevel
I have a GUIText- "play" on a scene called Title. When play is touched, I want the application to load the title scene. The following is the code that I have written and attached to the GUIText, and isn't working:
function Update(){
var count = iPhoneInput.touchCount; for (var i: int = 0; i < count; i++){ var touch : iPhoneTouch = iPhoneInput.GetTouch(i);
if (GUIText.HitTest( touch.position )){ Application.LoadLevel("Crush") } } }
Any ideas (please)?
Please elaborate on "isn't working". Do you get compile errors? Runtime errors? Other console output? Does the script work and it's just the level that's not loaded? Have you tried adding debug output into your script to find out where exactly it fails (not receiving touches, not intersecting the GUIText, etc.)?
No errors, what occurs is the game loads onto the iphone..it loads to the title screen and then you press the button..when this occurs the game either freezes..the screen goes black..or it simply crashes sending you back to the main iphone screen with all your other apps
Answer by Cyb3rManiak · Aug 11, 2010 at 03:14 PM
Well, without more info the first thing that comes to mind is that Update() is called each frame, and you might be calling the Application.LoadLevel("Crush") several times, instead of only once. Not sure about this, but it's worth checking out just in case.
Try adding some variable to see if it was already hit, like:
var bWasTextHit: boolean = false;
if (!bWasTextHit && GUIText.HitTest( touch.position )) { bWasTextHit = true; Application.LoadLevel("Crush") }
Answer by jtbentley · Aug 29, 2010 at 02:22 AM
Not to mention you might also be hitting it with more than one finger :)
I can confirm that I've had issues with Application.LoadLevels being triggered in Update loops without a toggling boolean.
Your answer
Follow this Question
Related Questions
How do Iake an object touch interactive 1 Answer
Degree from point? 2 Answers
touch to move camera, scroll over level 1 Answer
How do you map touch points to world space? 1 Answer
Detect screen tap vs. drag 2 Answers