Examples
For the examples in this chapter, I will cover two types of IMGUI usages: one for an in-game debug menu and another for an Inspector UI. All the examples covered up to this point have all been in-game debug menu UI.
Using IMGUI to show framerate in-game
Let’s create a very simple script that will show the frame rate of our game in the scene. It will change color if the framerate drops below a certain value.
To display the framerate in your game, complete the following steps:
- Create a new scene called
Chapter19-Examples.unity
. - Within the new scene, create a new GameObject called
DebugMenu
. - Create a new script called
DebugFrameRate.cs
. - Attach the
DebugFrameRate.cs
script to yourDebugMenu
GameObject as a component. - Open the new script and add the following variable declarations:
int fps; [SerializeField] int fpsThreshold;
The
fps
variable is used to get an estimate of our game’s frame rate, while thefpsThreshold
variable is assigned...