Pull request #18: Hide safe zone prompt when not appropriate

Merge in CEGJ/ludumdare50 from jason to dev

* commit '1811f3621f7c4db414344087c9c48a4a12944cb3':
  Hide safe zone prompt when not appropriate
This commit is contained in:
Jason Durand 01 2022-04-04 05:49:46 +00:00
commit b40f0567c4
2 changed files with 5 additions and 3 deletions

View File

@ -175,7 +175,7 @@ public class PlayerMovement : MonoBehaviour {
}
}
class NormalMovementState : BaseStatePlayerMovement {
public class NormalMovementState : BaseStatePlayerMovement {
public NormalMovementState(PlayerMovement playerMovement) : base(playerMovement) {}
public override void EnterState() {
@ -256,6 +256,7 @@ public class PlayerMovement : MonoBehaviour {
playerMovement.globalCamera.SetActive(true);
playerMovement.rb.SetEnabled(false);
safeZone.canvas.gameObject.SetActive(false);
}
protected override BaseState Transition() => new ImmobileMovementState(playerMovement);
@ -274,6 +275,7 @@ public class PlayerMovement : MonoBehaviour {
base.LeaveState();
playerMovement.rb.SetEnabled(true);
safeZone.canvas.gameObject.SetActive(true);
}
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);

View File

@ -6,7 +6,7 @@ public class SafeZone : MonoBehaviour {
public SafeZoneStats Stats { get; private set; }
[SerializeField] Collider2D moatCollider;
[SerializeField] RectTransform canvas;
[SerializeField] public RectTransform canvas;
public float OutsideDistance => moatCollider.bounds.extents.x + Stats.JumpOffset;
@ -19,7 +19,7 @@ public class SafeZone : MonoBehaviour {
}
private void OnTriggerStay2D(Collider2D other) {
if(!(other.GetComponent<VampireEntity>() is null)){
if(other.GetComponent<PlayerMovement>() is {} playerMovement && playerMovement.currentState is PlayerMovement.NormalMovementState){
Vector3 diff = (other.transform.position - transform.position);
//Player is in the zone around the moat
if(diff.magnitude >= moatCollider.bounds.extents.x){