Reputation: 23
I am making a game using the new input system, but I have gotten stuck when trying to have a button do two things.
Currently, I have an action map for gameplay, and the mouse click acts as the "fire" event. When the player clicks on a UI element (for example, an inventory slot), I don't want the "fire" event to occur, but rather another suitable method.
I tried to use two action maps (gameplay and UI), but I don't want the player to stop moving (due to gameplay input not being picked up on the UI action map).
I'm sure there is a simple solution to this, but there is a lack of extensive information on the new input system. I am thinking I may have to add an IPointer OnEnter, OnExit interface to the monobehaviour script and have the input script decide which action is best suited at the time of being pressed. Is there a more efficient way to do this?
Upvotes: 1
Views: 1475
Reputation: 4641
Put the responsibility on the Firing script to check that player state is valid. You can expose player state information in order to check if the player is in a menu or in some other state that does not allow Fire to happen.
CanFire
is a property in the player state composed from any number of checks.
public class PlayerState
{
.. other properties like IsInMenu, IsInCutscene, IsDead, etc..
public bool CanFire => !IsInMenu && !IsInCutscene && !IsDead;
}
Then in your firing script when the event is fired, check the CanFire boolean in the player state.
if (playerState.CanFire) Fire();
Upvotes: 1