- Home /
GUI Button Text in upper left?
I am working on my HUD and have a "spellbar" type setup similar to MMOs and was curious how I would go about getting the text of the button (in my case just the number on the keypad that corresponds to that button) in the upper left corner of said button, as well as the texture underneath it. Just starting out with GUI programming so not sure what all you can do with it.
If you need a little more help, or want more info on GUI, go here: http://docs.unity3d.com/Documentation/ScriptReference/GUI.html
Punkjim at the very bottom you just type the answer down there no need to hit add comment. That way people can give you credit for answering the question. Gives your profile $$anonymous$$arma.
As for your answer given I will have to give it a shot. I know how to do the mouse click OR input thing just needed the label information thanks.
Alright, ill move it to an answer, i had assumed you were the one to decide if it were an answer or not. :P
Your welcome.
Answer by Punkjim420 · Jan 22, 2013 at 10:59 PM
There are a few ways to do that. One way you could do it would be to place a texture on screen for each "button" then place labels on top of each texture. Now if you want them clickable you would check mouse position and if you click the mouse when its in your boxes(buttons) position then it should call the "activating the button" function. Then if you want corresponding keys to run that function you just create an if statement saying:
if(Input.GetKeyDown(KeyCode.1)){ activating the button function here(); }
for placing the texture youd do something like this in your OnGUI function:
GUI.DrawTexture(Rect(10,10,60,60), aTexture);
and for a Label: GUI.Label(Rect(10,10,60,60), "1");
for the texture script to work you have to have a variable thats "aTexture" in name, and type Texture2D so you can assign the image you want in the inspector. now you just need to look around a bit for a method to find mouse position to make the button "clickable" and you might want to change texture image if the mouse does click it, so it looks as if its being clicked.
Hope this is at least somewhat helpful... good luck.
Answer by Bunny83 · Jan 22, 2013 at 11:51 PM
The short answer is GUIStyle.alignment
I'm not familiar with GUI Styles how do I use that to put it in the upper left? The script reference doesn't refer to how to change it unless I'm to noob to notice it.
Your answer
Follow this Question
Related Questions
GUILayout Window Help 1 Answer
GUI Repeat Button problem 1 Answer
How do I fix my GUILayout.Button 2 Answers
How to put a GUILayout button BESIDE another one instead of below? 1 Answer
Unselect GUI Button 0 Answers