using Mirror; using UnityEngine; using UnityEngine.SceneManagement; [RequireComponent(typeof(Collider))] [RequireComponent(typeof(NetworkIdentity))] public class LocalPortal : NetworkBehaviour { [SerializeField] private string destinationSceneName = "PortalTestDestination"; [SerializeField] private string playerTag = "Player"; private bool transitionStarted; private void Awake() { Collider portalCollider = GetComponent(); portalCollider.isTrigger = true; Debug.Log($"[LocalPortal] Initialized '{name}' in scene '{SceneManager.GetActiveScene().name}'. " + $"Position: {transform.position}, Trigger: {portalCollider.isTrigger}, Destination: '{destinationSceneName}'", this); } [ServerCallback] private void OnTriggerEnter(Collider other) { Transform root = other.transform.root; Debug.Log($"[LocalPortal] Trigger entered by '{other.name}' (root: '{root.name}', tag: '{root.tag}') " + $"at position {root.position}. Portal position: {transform.position}. " + $"Current scene: '{SceneManager.GetActiveScene().name}'", this); if (transitionStarted) return; if (!root.CompareTag(playerTag)) { Debug.Log($"[LocalPortal] Ignoring '{root.name}' because its tag is '{root.tag}', expected '{playerTag}'.", this); return; } if (string.IsNullOrWhiteSpace(destinationSceneName)) { Debug.LogError("[LocalPortal] Destination scene is empty; scene transition cancelled.", this); return; } transitionStarted = true; Debug.Log( $"[LocalPortal] Server changing scene from '{SceneManager.GetActiveScene().name}' " + $"to '{destinationSceneName}' because '{root.name}' entered the portal.", this); NetworkManager.singleton.ServerChangeScene(destinationSceneName); } }