Checkpoint.cs 968 B

12345678910111213141516171819202122232425262728
  1. using UdonSharp;
  2. using UnityEngine;
  3. using VRC.SDKBase;
  4. [UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)]
  5. [DisallowMultipleComponent]
  6. [AddComponentMenu("Artyom Scripting System/Checkpoint")]
  7. public class Checkpoint : UdonSharpBehaviour
  8. {
  9. public GameObject targetObject; // The game object to move
  10. // Each player has their own progress, so this stays local: syncing it let one player's checkpoint block everyone's
  11. private bool hasBeenUsed = false;
  12. public override void OnPlayerTriggerEnter(VRCPlayerApi player)
  13. {
  14. if (hasBeenUsed || !player.isLocal) return;
  15. if (targetObject == null)
  16. {
  17. Debug.LogError("[AUMSS] Checkpoint: Target Object isn't assigned.");
  18. return;
  19. }
  20. targetObject.transform.SetPositionAndRotation(transform.position, transform.rotation);
  21. hasBeenUsed = true;
  22. gameObject.SetActive(false); // Hides the checkpoint for this player once used
  23. }
  24. }