Searching a Generic list for gameobject with a given name.

I have a generic list of gameobjects “Nodes”, and I need to find an object in that list with a given name. “trigger” is a string, and we basically need to see if any of the gameobjects’ names matches the value of trigger. Working in C# here.

I suppose it would be something along these lines?

	foreach (GameObject in Nodes)
	{
		if (Object.name == Trigger)
		{
			Debug.Log("Yay");
		}
	}

Not entirely sure how to phrase that first line though, the foreach loop. Any ideas? Thanks.

You’re pretty much there already, just have to specify the name of the variable being declared. For example:

foreach (GameObject obj in Nodes) {
    if (obj.name == Trigger) {
        Debug.Log("Yay");
    }
}