Checkpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Player controller.
|
||||
@@ -95,8 +96,8 @@ public class Player : MonoBehaviour
|
||||
[Tooltip("Current health points")]
|
||||
public int CurrentHealth;
|
||||
|
||||
[Tooltip("Checkpoint for respawn")]
|
||||
public Checkpoint Checkpoint;
|
||||
[Tooltip("Event on definitive die")]
|
||||
public UnityEvent OnDie;
|
||||
}
|
||||
|
||||
[SerializeField] private Settings _settings;
|
||||
@@ -203,6 +204,8 @@ public class Player : MonoBehaviour
|
||||
_groundCheckRayOffset = cc.center + Vector3.up * (-cc.height * .5f - cc.skinWidth + _settings.GroundTolerance);
|
||||
_groundCheckSphereOffset = cc.center + Vector3.up * (-cc.height * .5f + cc.radius - cc.skinWidth - _settings.GroundTolerance);
|
||||
_groundCheckRadius = cc.radius;
|
||||
|
||||
_health.CurrentHealth = _health.MaxHealth;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -297,16 +300,7 @@ public class Player : MonoBehaviour
|
||||
_state.CurrentState = PlayerState.Stunned;
|
||||
|
||||
if (duration > 0)
|
||||
Invoke(nameof(RecoverFromStun), duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recover from stun.
|
||||
/// </summary>
|
||||
public void RecoverFromStun()
|
||||
{
|
||||
if (_state.CurrentState == PlayerState.Stunned)
|
||||
_state.CurrentState = PlayerState.Idle;
|
||||
Invoke(nameof(Recover), duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -319,6 +313,43 @@ public class Player : MonoBehaviour
|
||||
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
|
||||
_state.Ground = null;
|
||||
_state.CurrentState = PlayerState.Eliminated;
|
||||
|
||||
Invoke(nameof(GoToCheckpoint), 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recover from stun.
|
||||
/// </summary>
|
||||
public void GoToCheckpoint()
|
||||
{
|
||||
if (Checkpoint.Active && _health.CurrentHealth > 0)
|
||||
{
|
||||
_health.CurrentHealth--;
|
||||
|
||||
transform.position = Checkpoint.Active.transform.position;
|
||||
|
||||
Debug.Log("Go to last checkpoint");
|
||||
|
||||
Recover();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Player is dead");
|
||||
|
||||
_health.OnDie.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recover from stun.
|
||||
/// </summary>
|
||||
public void Recover()
|
||||
{
|
||||
if (_state.CurrentState == PlayerState.Stunned ||
|
||||
_state.CurrentState == PlayerState.Eliminated)
|
||||
_state.CurrentState = PlayerState.Idle;
|
||||
|
||||
_references.Controller.enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user