- Home /
Unity Android Custom button touch screen going to one level instead of the level picked
My question is for Unity Android pro: How do I make a custom button from a plain or a GUI texture? Every time I tap the screen on say level 3 it goes to level one as if all plains or GUI textures are the same knowing my code for each one has a Application.LoadLevel(#); what am I doing or how do I fix this so I can pick one of the 5 levels without it going to just one level tapping the screen on any level.
This is my code:
function Update(){
if(Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Began)
{
focusObj=null;
var ray=Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit,100)) {
Application.LoadLevel(#);
}
}
}
Answer by NickHorn · May 21, 2011 at 03:35 AM
I believe I tryed that once. It worked fine running on the android remote but after built to an .apk file and installed it to the phone, every thing loaded fine but the touch events wouldn't work. How would one go about doing it as a raycast?
Answer by Mai hime · Jun 12, 2011 at 11:17 AM
In my main menu application on android i have 2 buttons with this code and it worked fine for me :
function OnGUI()
{
if(GUI.Button(new Rect (140,145,60,20),"Settings"))
{
Application.LoadLevel(1);
}
if(GUI.Button(new Rect (455,4,30,39),"play"))
{
Application.LoadLevel(2);
}
}
Your answer
Follow this Question
Related Questions
Three finger tap? 1 Answer
Problem with Android Keyboard/TextField 1 Answer
Android controls 1 Answer
Build an text editor in unity 3d 0 Answers
LoadLevel takes too long on Android 1 Answer