OnTriggerEnter2D check for Name

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);
	}
}

Don’t use names, use tags.

 if(other.gameObject.tag == "myTag")
 {
     //run this
 }

Hey

i may be wrong, but i doesn’t one of the objects also need a “RigidBody2D” component attached to detect collision?

but as Reynardz indicates it is good practise to use “Tags”, easier to manage within the Unity dashboard.

You need a rigidbody or rigidbody2d attached to at least one of the colliding objects to register collisions, even when using trigger collisions. One of the colliders should be a normal collider with a rigidbody, and the trigger should be a trigger collider.

Try changing method name from “void awake(){” to “void Awake(){” (capitalize)

Try adding Debug.Log line after method entry:
void OnTriggerEnter2D (Collider2D other)
{
Debug.Log(“Debugging OnTriggerEnter2D. other.gameObject.tag=”+other.gameObject.tag);