Setting Up the Default Inputs

The first thing to do is to create a setup script which will run once before any of your other scripts try to get input from cInput. Note that this setup script only needs to run once, so if you put it in the first scene the player will see (e.g., a splash screen or loading screen) then you don't need to include it in any other scenes. cInput will persist when changing scenes.

It is considered best practice to call Init() in your Awake() function to allow cInput to instantiate a GameObject and load any customized settings. After that, you can define all of your default settings in the Start() (or other) function, starting with defining actions with SetKey() followed by any axes with SetAxis(), similar to what's shown below:

void Awake() { // initialize cInput cInput.Init(); } void Start() { // this creates a new action called "Left" and binds A and Left Arrow to it cInput.SetKey("Left", "A", "LeftArrow"); // this uses Keys.D and Keys.RightArrow to accomplish something similar cInput.SetKey("Right", Keys.D, Keys.RightArrow); // creates a new axis using "Left" and "Right" actions cInput.SetAxis("Horizontal Movement", "Left", "Right"); }

More details on how to use SetKey() or SetAxis() can be found in the Script Reference.

Remember: An axis cannot be defined until after its actions have been defined.

For a full list of acceptable inputs (as strings) see the Valid Inputs section. Additionally, you can use the included Keys class to let autocomplete help you type in the correct keys. Many of the examples in this documentation take advantage of the Keys class.

results matching ""

    No results matching ""