Last updated
Last updated
To create and integrate a new state into the player movement system, follow the steps below:
Create a new C# script:
Navigate to Scripts > State System > Child States
and create a new C# script for your state named PlayerNewStateNameState.cs
.
Edit the new script:
Open the script and delete the MonoBehaviour inheritance as well as the Start() and Update() methods.
Make the new state class inherit from MainState.
Generate or write a constructor for the new state class:
Override virtual functions:
Generate or write overrides for Main State's virtual functions: Enter(), Update(), FixedUpdate(), Exit(), PhysicsCheck(), SwitchStateLogic().
Add custom logic:
Implement your custom logic using the overridden functions.
Create nested class in PlayerData (recommended):
If you want to create variables for the PlayerData class to control and tweak the new state, add a new nested class to the PlayerData script, keeping the structure consistent with the other nested variable classes.
Update PlayerMain.cs:
Open the PlayerMain.cs
script and update the AnimName
enum by adding the new state's animation bool name.
Declare the new state:
In the Awake()
method, initialize the new state:
Set up animations:
Open the "Player AC" located in the animations folder.
Create an empty state, connect entry and exit to it, and name it as your new state.
Add a new bool to the parameters with the same name as your new state's AnimBool variable.
Add enter and exit conditions to the new state in the animator.
Choose the new bool you added as the condition: Enter condition occurs when the bool is true, and exit when false.
For fast animation changes, in the transition to exit, untick "Has Exit Time" and set the "Transition Duration" to 0 seconds.
Now you have successfully added a new state to the player movement system! Implement your custom logic within the new state and fine-tune the animations to create unique gameplay experiences.