Advertisement
GoodNoodle

Location Portal

Sep 25th, 2023
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. public class LocationPortal : MonoBehaviour, IPlayerTriggerable
  2. {
  3.     // Teleports player without switching scenes
  4.     [SerializeField] DesID destinationPortal;
  5.    
  6.     [SerializeField] Transform spawnPoint;
  7.  
  8.     PlayerController player;
  9.     BuddyController buddy;
  10.  
  11.     [SerializeField] Fader fader;
  12.  
  13.  
  14.     private void Start()
  15.     {
  16.         fader = FindObjectOfType<Fader>();
  17.         player = FindObjectOfType<PlayerController>();
  18.         buddy = FindObjectOfType<BuddyController>();
  19.     }
  20.  
  21.     public void OnPlayerTriggered(PlayerController player)
  22.     {
  23.          
  24.             player.Charecter.Animator.IsMoving = false;
  25.             this.player = player;
  26.             StartCoroutine(Teleport());
  27.                
  28.     }
  29.  
  30.     IEnumerator Teleport()
  31.     {
  32.        // GameController.Instance.PauseGame(true);
  33.         yield return fader.FadeIn(0.5f);
  34.  
  35.        
  36.         var portal = FindObjectsOfType<LocationPortal>().First(x => x != this && x.destinationPortal == this.destinationPortal);
  37.         player.Charecter.SetPositionAndSnapToTile(portal.spawnPoint.position);
  38.         //StopBuddy();
  39.         yield return fader.FadeOut(0.5f);
  40.  
  41.  
  42.        // GameController.Instance.PauseGame(false);
  43.     }
  44.  
  45.     public void StopBuddy()
  46.     {
  47.       buddy.Charecter.Animator.IsMoving = false;
  48.         StartCoroutine(Teleport());
  49.     }
  50.  
  51.     public void OnCompanionTriggered(CompanionController companion)
  52.     {
  53.         companion.Charecter.Animator.IsMoving = false;
  54.         StartCoroutine(Teleport());
  55.     }
  56.  
  57.     public Transform SpawnPoint => spawnPoint;
  58.  
  59.     public bool triggerRepeatedly => false;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement