using UnityEngine; [RequireComponent(typeof(Collider))] public class TeleportPoint : MonoBehaviour { [Header("Destination")] public Transform destination; // set this to SkyCity_Spawn or any target [Header("Filtering")] public string requiredTag = "Player"; // only teleport objects with this tag [Header("Behavior")] public bool matchRotation = true; [Tooltip("Shared ID for A<->B portals to avoid instant ping-pong.")] public string portalId = "SkyCityGate"; [Tooltip("Seconds the entity cannot re-trigger a portal after using one.")] public float reentryCooldown = 0.5f; private void Reset() { var c = GetComponent(); c.isTrigger = true; } private void OnTriggerEnter(Collider other) { if (!IsAllowed(other.gameObject)) return; var tm = TeleportManager.Instance; if (tm == null) { Debug.LogWarning("[TeleportPoint] No TeleportManager in scene."); return; } if (!tm.CanUsePortal(other.gameObject, portalId, reentryCooldown)) return; tm.MarkUsed(other.gameObject, portalId, reentryCooldown); tm.Teleport(other.gameObject, destination, matchRotation); } private bool IsAllowed(GameObject go) { if (!string.IsNullOrEmpty(requiredTag) && !go.CompareTag(requiredTag)) return false; if (destination == null) { Debug.LogWarning($"[TeleportPoint] '{name}' has no destination assigned."); return false; } return true; } #if UNITY_EDITOR private void OnDrawGizmos() { if (destination == null) return; Gizmos.color = Color.cyan; Gizmos.DrawWireSphere(transform.position, 0.3f); Gizmos.DrawLine(transform.position, destination.position); Gizmos.DrawWireSphere(destination.position, 0.3f); } #endif }