So i am making a Platformer, and when you go through a green door you win. My problem is that i don’t know how to do that. I want to use the same script for every level, in level 1 the Trigger is called “Trigger01” in level 2 it is called “Trigger02”. So how do i detect the name of the Trigger?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WinGame : MonoBehaviour {
public void gback()
{
SceneManager.LoadScene ("LevelSelect");
}
void OnTriggerEnter2D (Collider2D other) {
if(other.gameObject.name == "Trigger01") {
SceneManager.LoadScene ("LevelSelect");
PlayerPrefs.SetString("Level02Lock", "enable");
}
if(other.gameObject.name == "Trigger02") {
SceneManager.LoadScene ("LevelSelect");
PlayerPrefs.SetString("Level03Lock", "enable");
}
}
void awake(){
DontDestroyOnLoad (transform.gameObject);
}
}