Find object by name + tag?

Im spawning prefabs of rooms. When spawned the rooms get assigned a tag number, ex. 1,2,3 etc… All of the children of the room, like doors for example, take on the tag of the parent room. For instance if going from one room to another I need to find the name and tag. I’m guessing I need to do some kind of array with find object.tag and throw in a loop? Didn’t have time to hatch it out thought I’d get some insight before trying!

Thanks in advance!

Hate to say this but have you actually tried typing the title of this question into Google with the word unity before it?

OK I’ll assume you know how to GameObject.Find and you’re actually unsure how to get the object because part of the way you’re trying to find it is the name and part is the tag.

You could loop a foreach with every object that matches the tag and then find the name you want in that or you could just set the name to Room_1, Room_2, Door_1, Door2 and so on. Then just use GameObject.Find(“Room_1”);

EDIT:

Sorry @aronatvw I just thought wow that’s basic! OK confusion over. I use this to search through child objects if it helps.

using UnityEngine;
using System.Collections;

public static class ExtensionMethods
{
	public static Transform Search(this Transform target, string name)
	{
		if (target.name == name) return target;
		
		for (int i = 0; i < target.childCount; ++i)
		{
			var result = Search(target.GetChild(i), name);
			
			if (result != null) return result;
		}
		
		return null;
	}
}

So if I look for the child transform to instantiate a spell from my player I call this:

_magicRHand = transform.Search("RHandBlade");

As the mount point for a sword matches where I want the spell to start.

EDIT 2:

And you can do foreach loop like this:

GameObject[] go = GameObject.FindGameObjectsWithTag("1");
		foreach(GameObject taggedOne in go)
                {
                    // Do you code here e.g.
                    Debug.Log(taggedOne.name);
                }

Hope some of that helps.

A quick and easy way is to set a collider around each room and use the OnTriggerEnter-Method to see if the player is switching rooms, also you would be able to access the tag and the name of the room, by using the collider-argument of the method.
Hope you know what I mean.