- Home /
functions inside functions
how do i call the OnGUI function from inside a function
fuction Update (){
....................... .................... ..................
if blah blah is true
function OnGUI () {
GUI.Box (Rect (10,10,100,90), "like this ");
}
}
i really dont understand why nothing i try works .
Answer by Berenger · Feb 05, 2012 at 06:12 PM
A functeption !
There is a bunch of function prepared for you by Unity (Update, Start, Awake, OnGUI, FixedUpdate etc) which are called by Unity at a specific time, without you seeing that call. So all you have to do, is implement them, and let good guy Unity take care of the rest.
By the way, you can't declare a function inside an other one. Declare Update(), implement it {}, then declare OnGUI(), and implement it as well {}.
Answer by GutoThomas · Feb 05, 2012 at 06:44 PM
You don't need to call OnGUI inside Update function(and it will not work, actually) to add an if statement. You can add if statement inside GUI function, like so:
function OnGUI() {
if(blah blah) {
GUI.Box (Rect (10,10,100,90), "like this "); }
`}
Hope is that what you're looking for (:
@Guto$$anonymous$$ thanks for helping, even though you are new. :)
But please, both you and @Alanimator, learn to format
(I know UnityAnswers' Instructions FAIL... -.- )
Either indent each line of code with four spaces or use html tags.
Didn't know about the tag. This will save me lots of trouble indenting manually each answer.
@$$anonymous$$ryptos: just select code and hit the code button, you don't need to manually do anything or use code tags.