I am new to Game Development and Unity. I have written a component for Jumping and Running, CharacterJumpAbility.cs
and CharacterRunAbility.cs
.
I would like the Character to be able to Jump only if the Character is not moving. I came across a State Pattern but I can't understand how to apply it. For example if I want to Jump, first I must check if the Character is Running, but I have to do this in the CharacterJumpAbility.cs
or in the CharacterController.cs
(the component who handles inputs)?
If I define a state for example:
public enum CharacterState {
Run,
Jump
}
For example if the player is pressing the space bar, I have to set the Jump state, the code that sets state = CharacterState.Jump
should be written in the CharacterJumpAbility.cs
or in the component that handles inputs?
And if I want to set a new state for example Jump, while I am running, this is clearly not possible, how to handle situations like these?