Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class LevelLoader : MonoBehaviour
- {
- private bool playerInZone;
- public string levelToLoad;
- void Start()
- {
- playerInZone = false;
- }
- void Update()
- {
- if (Input.GetAxisRaw("Vertical") > 0 && playerInZone)//&& Input.GetKey(KeyCode.W))
- {
- // Load the level when 'W' key is pressed and player is in the zone
- //Application.LoadLevel(levelToLoad);// Load the level gives warning dude to update
- SceneManager.LoadScene(levelToLoad);// Load the level gives error for SceneManager
- }
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.name == "Player")
- {
- // Set playerInZone to true when the player enters the trigger zone
- playerInZone = true;
- }
- }
- void OnTriggerExit2D(Collider2D other)
- {
- if (other.name == "Player")
- {
- // Set playerInZone to false when the player exits the trigger zone
- playerInZone = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement