using UdonSharp; using UnityEngine; using VRC.SDKBase; [UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)] [AddComponentMenu("Artyom Scripting System/Timed Teleport")] [DisallowMultipleComponent] public class TimedTeleport : UdonSharpBehaviour { [Header("Teleportation Settings")] public Transform teleportTarget; // The transform to teleport the player to public float delay = 1f; // The delay in seconds before teleportation [Tooltip("Leaving the trigger before the delay is up cancels the teleport.")] public bool cancelOnExit = false; private bool pending; // A teleport is waiting: entering again doesn't queue another public override void OnPlayerTriggerEnter(VRCPlayerApi player) { if (!player.isLocal || pending) return; if (teleportTarget == null) { Debug.LogError("[AUMSS] Timed Teleport: Teleport Target isn't assigned."); return; } pending = true; SendCustomEventDelayedSeconds(nameof(TeleportPlayer), delay); } public override void OnPlayerTriggerExit(VRCPlayerApi player) { if (cancelOnExit && player.isLocal) pending = false; } public void TeleportPlayer() { if (!pending) return; // Cancelled by leaving the trigger pending = false; Networking.LocalPlayer.TeleportTo(teleportTarget.position, teleportTarget.rotation, VRC_SceneDescriptor.SpawnOrientation.Default, false ); } }