- Home /
GUI Text as Button
Hi There,
In need of major help, so ive made a menu with three GUI texts saying easy, medium and hard, what i want is that when ever the player taps one of the texts it loads a scene, this is the code i have already, but it wont work, the scene i want to go to is in the build settings.
using UnityEngine; using System.Collections;
public class EasyButton : MonoBehaviour {
void OnMouseDown()
{
//load the level named "Tappy Plane New"
Application.LoadLevel("Tappy Plane New");
}
}
What about it doesn't work? What version of Unity are you using? Using On$$anonymous$$ouseDown for touch input isn't functional unless you're using Unity 4 or later.
Hi, im using unity 4, but every time i use the void On$$anonymous$$ouseDown function and try to click easy on my main men it doesnt go to tappy plane new
Did you do any basic debugging to see what's happening? Such as putting Debug.Log ("Used easy button")
inside the On$$anonymous$$ouseDown function.
Answer by tw1st3d · Apr 20, 2014 at 01:17 AM
You need to use a GUI.Button();
GUI_Button_Style is optional.
In Javascript:
function OnGUI() {
if(GUI.Button( Rect( OFFSET-LEFT, OFFSET-TOP, WIDTH, HEIGHT), "GUI_BUTTON_TEXT", GUI_BUTTON_STYLE)) {
Application.LoadLevel("Tappy Plane New");
}
}
In C#:
void OnGUI() {
if(GUI.Button(new Rect( OFFSET-LEFT, OFFSET-TOP, WIDTH, HEIGHT), "GUI_BUTTON_TEXT", GUI_BUTTON_STYLE)) {
Application.LoadLevel("Tappy Plane New");
}
}
Hi,
I tried the button thing, and when I test it on my bb z10 device the buttons are really small, so I thought I would use gui text, any way that I can gui button fucntions to the gui text, without having the button style
Hi,
I tried the button thing, and when I test it on my bb z10 device the buttons are really small, so I thought I would use gui text, any way that I can gui button fucntions to the gui text, without having the button style
Converted your answer to comment. Please remember to use the comment button under someones answer ins$$anonymous$$d. :)
I'm unaware of any way to do that, however that does not mean that there is no way to do it. If I were you, I'd create a new GUISkin, and create a custom style for the buttons. You can adjust their font size, color, background image, and active/hover/focus states. Just create large enough buttons to be the proper size.
alright, i will try to do that again, cause i previously tried resizing it and it didnt make much of a difference. I washopeing to do it the gui text way but its alright
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Unity's GUI Icons are Blurry..? 1 Answer
GUI how to make the scrollbar bigger? 1 Answer
DragWindowPosition Doesn't Work 1 Answer