So I have a script that has a string that can be modified from the inspector. I want this string to be used to find the name of a gameObject.
public string SceneEntrance; //scene entrances are the collider triggers that load new scenes
void OnTriggerEnter2D (Collider2D other)
{
if(other.gameObject.name == “SceneEntrance”) //the string chooses the name of the gameObject
{
Destroy(this.gameObject)
}
}
Basically, I want the name of the game object to match my string name, but instead of searching for the string’s name,(example: SceneEntrance.name = Box) it just searches for a gameObject that is literally called “SceneEntrance” (instead of “Box” or whatever I put as the string’s name)
How do I make the string’s name represent the gameobject’s name?