- Home /
This post has been wikified, any user with enough reputation can edit it.
Organizing OnGUI into Multiple Functions
"You can only call GUI functions from inside OnGUI"
I would love to put OnGUI into multiple functions, so it's not so messy, for example:
public class GUIStuff : MonoBehaviour {
void OnGUI() {
CrossHair();
HealthBar();
}
private void CrossHair() {
// obviously not a significant amount of code, but just an example!
}
private void HealthBar() {
}
}
Comment
What you are doing here should work fine...as long as the method calls are made from within the OnGUI() callback.
I remember having issues with this a while back, so if it should work, then I'm not sure what happened before. Thank you for the response.