Advertisement
GoodNoodle

Portal

Sep 25th, 2023
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. public class Portal : MonoBehaviour, IPlayerTriggerable
  2. {
  3.     [SerializeField] int sceneToLoad = -1;
  4.     [SerializeField] DesID destinationPortal;
  5.     [SerializeField] Transform spawnPoint;
  6.  
  7.     PlayerController player;
  8.  
  9.     Fader fader;
  10.     public void OnPlayerTriggered(PlayerController player)
  11.     {
  12.         player.Charecter.Animator.IsMoving = false;
  13.         this.player = player;
  14.         StartCoroutine(SwitchScene());
  15.     }
  16.  
  17.     private void Start()
  18.     {
  19.       fader =  FindObjectOfType<Fader>();
  20.     }
  21.     IEnumerator SwitchScene()
  22.     {
  23.         DontDestroyOnLoad(gameObject);
  24.  
  25.          GameController.Instance.PauseGame(true);
  26.         yield return fader.FadeIn(0.5f);
  27.  
  28.         yield return SceneManager.LoadSceneAsync(sceneToLoad);
  29.  
  30.         var portal = FindObjectsOfType<Portal>().First(x => x != this && x.destinationPortal == this.destinationPortal);
  31.         //player.Charecter.SetPosToTile(portal.spawnPoint.position);
  32.  
  33.         yield return fader.FadeOut(0.5f);
  34.  
  35.         GameController.Instance.PauseGame(false);
  36.  
  37.         Destroy(gameObject);
  38.     }
  39.  
  40.     public void OnCompanionTriggered(CompanionController companion)
  41.     {
  42.         throw new System.NotImplementedException();
  43.     }
  44.  
  45.     public Transform SpawnPoint => spawnPoint;
  46.  
  47.     public bool triggerRepeatedly => false;
  48. }
  49.  
  50. public enum DesID
  51. {
  52.     a,
  53.     b,
  54.     c,
  55.     d,
  56.     e,
  57.     f,
  58.     g,
  59.     h,
  60.     i,
  61.     j,
  62.     k,
  63.     l,
  64.     m,
  65.    
  66. }
  67.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement