Game Development Reference
In-Depth Information
Adding the Reset function
The reset function will use our SetDefaultValues() function as well as reset a
couple of our other variables:
void Reset()
{
SetDefaultValues();
ShowPopup = false;
PreviousKey = KeyCode.None;
}
Here, we call our SetDefaultValues() function, and then reset some other vari-
ables. Resetting the ShowPopup Boolean and our PreviousKey KeyCode will en-
sure that everything related to customization of controls has been reset.
Adding the Reset input
Now, we'll make a GUI button that will call the Reset function. Add this just before
the line of code that ends the GUI group in the OnGUI() function's if statement:
if(GUI.Button(new Rect(230, 370, 135, 20),
"Reset Controls"))
{
Reset();
}
When the player clicks on this button, the controls will be set to their default values.
Here is the finished product of the script that you just created:
Search WWH ::




Custom Search