Usually, the very first input that is required from a player in most games is from buttons on the main menu of a game. Thus, we are now going to create our own buttons using the OnGui
function provided by Unity.
The OnGUI
function is used for handling GUI events, the creation and the look and functionality of the game's GUI. It is an event function that is part of the well-defined set of callbacks that Unity provides, so it gets called automatically like Start()
and Update()
. We, therefore, do not call it within another function.
OnGUI
can be called several times per frame depending on its implementation. It will get called once per GUI event.