- Home /
Level Button And Quit Button Android
Hey I am making a game for Android and on my main menu I have three buttons, Campaign, Options and Quit. I am very bad at coding, and have almost no experience in coding. I have made some other games for android and PC, but the buttons on the Android games were really simple, as they were just tap anywhere to play. but I have looked around everywhere for this and i can't find any answers. Could someone help me? All i need is a code to quit the app and a code when i press the GUI Text it goes to the level i want.
Thanks!
C#:
Closing: Application.Quit();
Level: Application.LoadLevel(numberOfLevel);
That's the beauty of it, Unity takes Input.mouseButton(0) as a touch, the same way it takes it as a click on a pc.
Ok That Helps Sooo $$anonymous$$uch Thanks, i never knew that!
Answer by Serdnad · Jul 31, 2014 at 08:46 PM
Same way you would do it for a PC Game.
void OnGUI ()
{
if(GUI.Button(new Rect(Screen.width/8, Screen.height/2, Screen.width/4, Screen.height/4), "Level 1"))
{
Application.LoadLevel("Level 1");
}
else if(GUI.Button(new Rect(Screen.width/2, Screen.height/2, Screen.width/4, Screen.height/4), "Quit"))
{
Application.Quit();
}
}
Just change the positions and widths, and that should be good. And you can make it look better by using your own picture, or playing with the font and borders and colors, in which case you should look up GUIStyle if you're interested in that.
Also, the else in the second if statement is optional, but since it's impossible to click both buttons at the exact same time, it does no harm.
@ReflexGames, Glad I was able to help :). Would you $$anonymous$$d marking it correct if it answered your question?
Answer by keburanuil · Jul 31, 2014 at 08:47 PM
var levelToLoad : int;
var quitButton : boolean;
function OnMouseDown()
{
if (quitButton)
Application.Quit();
else
Application.LoadLevel(levelToLoad);
}
Add this script to your buttons and setup it in inspector. Works on pc/mac and mobile.
Your answer
Follow this Question
Related Questions
Gui text script - help 1 Answer
[Android] Why does my enemy die no matter where I am in the 3D environment? 1 Answer
Using "fonts" that are actually images for a multi-outline effect. 2 Answers
Zoom at Text 1 Answer
GUI HELP!!!!! 1 Answer