I’m working on a player health script for my in game player (just a cube, at the moment). However, I have run into a barrier.
// Update is called once per frame
void Update () {
if ( Input.GetKeyDown("h"))
{
ShowHealth();
}
}
When the key “h” is touched, I want “ShowHealth();” to happen. I tried:
void ShowHealth();
{
// Show what I want to appear via GUI
}
But then I found out GUI functions must be called with “void OnGUI()”. But my question is how would I create a function, in C# of course, inside the GUI?
If I’m understanding you correctly, I think you just need a little point-of-view change on event-driven design. The OnGUI() function will be triggered once (or more) per frame and the Update() also once per frame. You’re not going to be calling GUI drawing methods from the Update() routines. Instead, you want to have flags that can be set/modified by the Update() routines that determine what the GUI routines call: