Game Development Reference
In-Depth Information
}
break;
}
}
As you can see, this function is very similar to our
SetDefaultValues()
function;
it acts the same way.
SwitchControlScheme()
takes a string that determines
which control scheme to use and then assigns the appropriate data. The first scheme
is the default control scheme, while the other one is a new scheme. The new scheme
changes the following:
• Item keys are now on the keypad
• Inventory buttons are now the
+
key and
B
key
• Attack/use inputs are switched on the mouse
• Pause has been changed to the
Enter
key and the Backspace key
Adding a control switch button to the GUI
Lastly, we'll need to add a GUI button to our
OnGUI
function to allow the player to
switch control schemes. Add the following before the line that ends the group:
GUI.Label(new Rect(15, 345, 125, 20), "Current
Control Scheme");
if(GUI.Button(new Rect(25, 370, 135, 20),
ControlScheme))
{
if(ControlScheme == "Scheme A")
{
SwitchControlScheme("B");
ControlScheme = "Scheme B";
}
else
{
SwitchControlScheme("A");
ControlScheme = "Scheme A";
}
}