added self heal
This commit is contained in:
@@ -10,7 +10,7 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
[SerializeField] private string actionMapName = "Player";
|
||||
[SerializeField] private string moveActionName = "Move";
|
||||
[SerializeField] private string jumpActionName = "Jump";
|
||||
[SerializeField] private string healActionName = "Crouch";
|
||||
[SerializeField] private string healActionName = "Heal";
|
||||
[SerializeField] private string controlSchemeName = "";
|
||||
[SerializeField] private int gamepadIndex = -1;
|
||||
[SerializeField] private float moveSpeed = 6f;
|
||||
@@ -19,6 +19,7 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
[SerializeField] private float groundCheckDistance = 0.05f;
|
||||
|
||||
private PlayerStressController playerStressController;
|
||||
private PlayerPickupController playerPickupController;
|
||||
|
||||
private Rigidbody2D body;
|
||||
private BoxCollider2D bodyCollider;
|
||||
@@ -28,12 +29,16 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
private InputAction healAction;
|
||||
public float LastMoveX { get; private set; }
|
||||
private bool deviceFilterEnabled;
|
||||
private int healCoolDownTicks = 15;
|
||||
private int currentHealCoolDown = 0;
|
||||
private bool canHeal = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
body = GetComponent<Rigidbody2D>();
|
||||
bodyCollider = GetComponent<BoxCollider2D>();
|
||||
playerStressController = GetComponent<PlayerStressController>();
|
||||
playerPickupController = GetComponent<PlayerPickupController>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -56,10 +61,12 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
var map = runtimeActions.FindActionMap(actionMapName, true);
|
||||
moveAction = map.FindAction(moveActionName, true);
|
||||
jumpAction = map.FindAction(jumpActionName, true);
|
||||
healAction = map.FindAction(healActionName, true);
|
||||
|
||||
moveAction.Enable();
|
||||
jumpAction.Enable();
|
||||
jumpAction.performed += OnJumpPerformed;
|
||||
healAction.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -75,6 +82,11 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
moveAction.Disable();
|
||||
}
|
||||
|
||||
if (healAction != null)
|
||||
{
|
||||
healAction.Disable();
|
||||
}
|
||||
|
||||
if (runtimeActions != null)
|
||||
{
|
||||
runtimeActions.Disable();
|
||||
@@ -86,6 +98,16 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (healAction == null) return;
|
||||
|
||||
currentHealCoolDown++;
|
||||
|
||||
if (currentHealCoolDown >= healCoolDownTicks)
|
||||
{
|
||||
currentHealCoolDown = 0;
|
||||
canHeal = true;
|
||||
}
|
||||
|
||||
if (moveAction == null)
|
||||
{
|
||||
return;
|
||||
@@ -93,6 +115,22 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
|
||||
if (playerStressController.isPanicking) return;
|
||||
|
||||
if (healAction.IsPressed())
|
||||
{
|
||||
if(playerPickupController.heldObject != null)
|
||||
{
|
||||
playerPickupController.DropObject(false);
|
||||
}
|
||||
|
||||
if (canHeal)
|
||||
{
|
||||
playerStressController.ReduceStress(1f);
|
||||
canHeal = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var input = moveAction.ReadValue<Vector2>();
|
||||
if (Mathf.Abs(input.x) > 0.01f)
|
||||
{
|
||||
@@ -105,7 +143,7 @@ public class PlayerPlatformerController : MonoBehaviour
|
||||
|
||||
private void OnJumpPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (playerStressController.isPanicking) return;
|
||||
if (playerStressController.isPanicking || healAction.IsPressed()) return;
|
||||
|
||||
if (!IsGrounded())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user