- Home /
GUI Button in the middle of screen?
is it possible? here's my code..
---CODE---
var centeredStyle2 = GUI.skin.GetStyle("Button");
if(GUI.Button (Rect (Screen.width/2-50, Screen.height/2+10, 100, 50), "Halloa", centeredStyle2)
{
Application.LoadLevel(0);
}
Comment
Best Answer
Answer by Kleptomaniac · Apr 04, 2012 at 01:46 PM
Yes it is indeed possible, other than the fact that the button needs to be rendered in OnGUI and you need an extra bracket in the GUI.Button line. So like this:
var centeredStyle2 = GUI.skin.GetStyle("Button");
function OnGUI () {
if(GUI.Button (Rect (Screen.width/2 - 50, Screen.height/2 + 10, 100, 50), "Halloa", centeredStyle2)) {
Application.LoadLevel(0);
}
}
Other than that, you're all good. ;)
Hope that helps, Klep
if (GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height / 2 + 10, 100, 50), "Halloa"))
why don't you use "new Rect"
Your answer
Follow this Question
Related Questions
GUI button in middle of screen 2 Answers
Screen Sizes - HUD - Button Layout - Camera. 0 Answers
Clicking Trigger 1 Answer
How do you auto scale the space between Gui Buttons? 1 Answer