- Home /
Setting a button size via script
Hi, i tried to make a main menu for an android game, and found a problem. I wanted to make some buttons' size(4 in total) to be equal to the canvas height/4, but i don't know how to set the size.
example.png
(12.0 kB)
Comment
Answer by toddisarockstar · Apr 10, 2016 at 05:55 AM
var sx:float;
var sy:float;
var but:int;
function OnGUI() {
sx=Screen.width;
sy=Screen.height;
GUI.Label(Rect(sx*0.5,sy*0.5,sx*0.25,sy*0.25),"number "+but);
if( GUI.Button(Rect(0,sy*0.00,sx*0.25,sy*0.25),"press me")){but=1;}
if( GUI.Button(Rect(0,sy*0.25,sx*0.25,sy*0.25),"press me")){but=2;}
if( GUI.Button(Rect(0,sy*0.50,sx*0.25,sy*0.25),"press me")){but=3;}
if( GUI.Button(Rect(0,sy*0.75,sx*0.25,sy*0.25),"press me")){but=4;}
}
Oh, i forgot to say i use c#, but i'll try to search the equivalent of these functions in the scripting reference
Your answer
Follow this Question
Related Questions
Get height and width of gameobject set with anchors 0 Answers
How to change the Width and Height in the script C#? (New Gui Unity 4.6 beta) 2 Answers
Buttons stopped working after I temporarily changed the font. 1 Answer
Inventory UI buttons not working 1 Answer
Getting height and width of images 1 Answer