Advertisement
ChrisTutorials

LevelMove C# Unity

Dec 29th, 2021
5,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class LevelMove_Ref : MonoBehaviour
  7. {
  8.     public int sceneBuildIndex;
  9.  
  10.     // Level move zoned enter, if collider is a player
  11.     // Move game to another scene
  12.     private void OnTriggerEnter2D(Collider2D other) {
  13.         print("Trigger Entered");
  14.        
  15.         // Could use other.GetComponent<Player>() to see if the game object has a Player component
  16.         // Tags work too. Maybe some players have different script components?
  17.         if(other.tag == "Player") {
  18.             // Player entered, so move level
  19.             print("Switching Scene to " + sceneBuildIndex);
  20.             SceneManager.LoadScene(sceneBuildIndex, LoadSceneMode.Single);
  21.         }
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement