Changing Inputs from the Defaults
One of the headlining features of cInput is that it enables you to change key bindings at runtime, a feature sorely missing from Unity
Changing Inputs via Script
For information on how to change key bindings from script, see the ChangeKey()
documentation.
Using the Built-In GUI
cInput comes with a built-in GUI to make it simple to change which inputs are bound to which actions. This is great for rapid prototyping since it allows you to adjust the controls at runtime without having to invest a lot of time into a custom GUI.
Due to popular demand, we've separated this built-in GUI from the main cInput
class into it's own class called cGUI
. Simply call cGUI.ToggleGUI()
to show or hide the built-in GUI menu, and assign a GUISkin to cGUI.cSkin
to change the way it looks. cInput includes a GUISkin for your convenience. You can also optionally change the color/alpha of the GUI using cGUI.bgColor
. For more specific information on how to use cGUI, please see the cGUI Reference Manual included in the .unitypackage
.
Making a Custom GUI Menu
Admittedly, even though you can customize the look of the built-in GUI with cGUI.cSkin
, it still won't fit the design or theme for every game. In situations like these where you're past the prototyping phase and getting closer to public release, it will likely be necessary (not to mention recommended) to replace the built-in GUI with something that fits the style of the rest of your game. With that in mind, cInput includes functions which will assist in the process of making your own custom GUI menu for changing controls.
A quick note: Explaining how to make a UI in Unity is beyond the scope of this document. To learn more about how to make GUIs in Unity, see the UI System or the Legacy GUI Scripting Guide sections in the online Unity Reference Manual. This section only explains the methods which cInput provides to assist you in making your own UI menu for displaying and changing the key bindings in your game. Also note that if you make your own UI, you can prevent cInput from adding its own included GUI components by using cInput.Init(false)
in your setup script.
There are a few methods and properties you will likely want to use when creating a UI to display the current key bindings and allow the players to change them or reset them back to defaults. They are the GetText()
, ChangeKey()
, ResetInputs()
functions and the length
property. You may also be interested in the OnKeyChanged
event.
The basic idea is to use a for
loop to iterate through all of the inputs and create buttons the player can click in order to change the key bindings while in game. Here is an example with Unity's legacy GUI:
Last updated