using NaughtyAttributes; using UnityEngine; public class SafeZone : MonoBehaviour { [field: SerializeField] [field: Required] public SafeZoneStats Stats { get; private set; } [SerializeField] Collider2D moatCollider; [SerializeField] RectTransform canvas; public Vector3 GetOutsidePosition(Vector2 direction) { return transform.position + (moatCollider.bounds.extents.x + Stats.JumpOffset) * (Vector3)direction; } public Vector3 GetMoatExtents(){ return moatCollider.bounds.extents; } private void OnTriggerStay2D(Collider2D other) { if(!(other.GetComponent() is null)){ Vector3 diff = (other.transform.position - transform.position); //Player is in the zone around the moat if(diff.magnitude >= moatCollider.bounds.extents.x){ //Spawn ui message over moat Vector3 dir = diff.normalized; Vector3 position = transform.position + dir * moatCollider.bounds.extents.x * 0.75f; Debug.DrawLine(transform.position, position, Color.red); canvas.position = position; canvas.gameObject.SetActive(true); } } } private void OnTriggerExit2D(Collider2D other) { if(!(other.GetComponent() is null)){ canvas.gameObject.SetActive(false); } } }