change to state machine
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
using CSNetwork.Protocols;
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
@@ -17,6 +18,9 @@ public class CharacterCtrl : MonoBehaviour
|
||||
[SerializeField] private Button btnJump;
|
||||
[SerializeField] private Button btnRun;
|
||||
|
||||
PlayerStateMachine playerStateMachine;
|
||||
PlayerMoveState moveState;
|
||||
|
||||
float playerSpeed = 5.0f;
|
||||
float jumpHeight = 1.5f;
|
||||
float gravityValue = -9.81f;
|
||||
@@ -25,8 +29,16 @@ public class CharacterCtrl : MonoBehaviour
|
||||
bool isGrounded = false;
|
||||
bool isRun = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
moveState = new PlayerMoveState(this);
|
||||
playerStateMachine = new PlayerStateMachine();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerStateMachine.InitState(moveState);
|
||||
|
||||
//btnJump.onClick.AddListener(HandleJump);
|
||||
}
|
||||
|
||||
@@ -71,6 +83,10 @@ public class CharacterCtrl : MonoBehaviour
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
playerStateMachine.UpdateState();
|
||||
}
|
||||
public void HandleMovement()
|
||||
{
|
||||
isGrounded = controller.isGrounded;
|
||||
|
||||
@@ -119,9 +135,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
playerVelocity.y += gravityValue * Time.deltaTime;
|
||||
Vector3 finalMove = (move * playerSpeed) + (playerVelocity.y * Vector3.up);
|
||||
controller.Move(finalMove * Time.deltaTime);
|
||||
|
||||
}
|
||||
|
||||
private void SetAnimIdle()
|
||||
{
|
||||
if(stateAnim == StateAnim.Idle || !isGrounded)
|
||||
|
||||
Reference in New Issue
Block a user