74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
[RequireComponent(typeof(Collider))]
|
|
public class TeleportPoint : MonoBehaviour
|
|
{
|
|
// [Header("Destination")]
|
|
// public Transform destination;
|
|
// set this to SkyCity_Spawn or any target
|
|
[Header("Destination")]
|
|
public string sceneToLoad = "IceTemple"; // Name of the scene to load
|
|
|
|
[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<Collider>();
|
|
c.isTrigger = true;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag(requiredTag))
|
|
{
|
|
SceneManager.LoadScene(sceneToLoad);
|
|
}
|
|
//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);
|
|
}
|
|
public void SetDestinationScene(string newSceneName)
|
|
{
|
|
sceneToLoad = newSceneName;
|
|
}
|
|
|
|
//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
|
|
} |