74 lines
2.3 KiB
C#
Raw Normal View History

using UnityEngine;
2025-09-26 23:37:09 +05:00
using UnityEngine.SceneManagement;
[RequireComponent(typeof(Collider))]
public class TeleportPoint : MonoBehaviour
{
2025-09-26 23:37:09 +05:00
// [Header("Destination")]
// public Transform destination;
// set this to SkyCity_Spawn or any target
[Header("Destination")]
2025-09-26 23:37:09 +05:00
public string sceneToLoad = "IceTemple"; // Name of the scene to load
[Header("Filtering")]
public string requiredTag = "Player"; // only teleport objects with this tag
2025-09-26 23:37:09 +05:00
//[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<Collider>();
c.isTrigger = true;
}
private void OnTriggerEnter(Collider other)
{
2025-09-26 23:37:09 +05:00
if (other.CompareTag(requiredTag))
{
SceneManager.LoadScene(sceneToLoad);
}
//if (!IsAllowed(other.gameObject)) return;
2025-09-26 23:37:09 +05:00
//var tm = TeleportManager.Instance;
//if (tm == null) { Debug.LogWarning("[TeleportPoint] No TeleportManager in scene."); return; }
2025-09-26 23:37:09 +05:00
//if (!tm.CanUsePortal(other.gameObject, portalId, reentryCooldown)) return;
2025-09-26 23:37:09 +05:00
//tm.MarkUsed(other.gameObject, portalId, reentryCooldown);
//tm.Teleport(other.gameObject, destination, matchRotation);
}
2025-09-26 23:37:09 +05:00
public void SetDestinationScene(string newSceneName)
{
2025-09-26 23:37:09 +05:00
sceneToLoad = newSceneName;
}
2025-09-26 23:37:09 +05:00
//private bool IsAllowed(GameObject go)
//{
// if (!string.IsNullOrEmpty(requiredTag) && !go.CompareTag(requiredTag))
// return false;
2025-09-26 23:37:09 +05:00
// if (destination == null)
// {
// Debug.LogWarning($"[TeleportPoint] '{name}' has no destination assigned.");
// return false;
// }
2025-09-26 23:37:09 +05:00
// 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
}