The OnKeyChanged Event

cInput calls an event whenever either the ChangeKey() function which waits for player input, or the ResetInputs() function is called. Note that it will still be called in cases where the keys stay the same (such as from canceling a ChangeKey() action). An example for why you might want to use the OnKeyChanged event would be to run a function to update the text labels in a custom UI.

Here's some code showing one such example:

// subscribe to the OnKeyChanged event void OnEnable() { cInput.OnKeyChanged += UpdateGUITexts; } // unsubscribe to the OnKeyChanged event so we don't cause errors void OnDisable() { cInput.OnKeyChanged -= UpdateGUITexts; } void UpdateGUITexts() { // put your code here to update the GUI texts when the OnKeyChanged event is fired }

What's an Event?

If events are completely new to you, you may find Unity's training video on Events helpful.

results matching ""

    No results matching ""