Game Development Reference
In-Depth Information
Adding a profile switching function
Next, we'll add a function that we can call to manually switch the control profile. Add
this function to our code:
void SwitchProfile (ControlProfile Switcher)
{
cProfile = Switcher;
}
We can call this function later to let the player choose between using the keyboard/
mouse or the Xbox 360 Controller.
Adding the GUI interaction function
Now, we'll add a button to the bottom right of our controls page to let the player
pick between the keyboard/mouse and Xbox 360 Controller. Add this code to your
onGUI() function, just before the line where we end the group:
GUI.Label(new Rect(450, 345, 125, 20), "Current
Controls");
if(GUI.Button(new Rect(425, 370, 135, 20),
cProfile.ToString()))
{
if(cProfile == ControlProfile.Controller)
SwitchProfile(ControlProfile.PC);
else
SwitchProfile(ControlProfile.Controller);
}
The text on the button will display which current control profile is being used. When
the player clicks on the button, it will switch the control profile.
Search WWH ::




Custom Search