Hey Unity members! So I’m having a bit of an issue, and I’ll try to explain what I mean as clear as possible. Please feel free to ask for more information.
First what I’m trying to do is similar to an old Zelda game where you move room to room via doors. So I have a prefab that contains 4 walls and a floor. First I spawn all my rooms, then I check to see which neighbors each room has. So let’s say that this room has a neighbor to the north. What I want to do is spawn a prefab of a wall that contains a door + wall and destroy the old wall that used to be there.
The problem I’m having is accessing the old wall. I thought maybe I’d be able to do something such as:
GameObject oldWall = room.GetComponent("NorthWall") as GameObject;
NorthWall itself is actually a GameObject inside of my Room prefab. When I try to do this I get an error that I can’t convert Component to GameObject or vise versa.
So then I thought maybe I could do:
Component oldWall = Room.GetComponent("NorthWall") as GameObject;
In doing that though when I try to access the Transform it comes back as Null.
When trying to google around I’ve seen people saying use:
foreach(GameObject room in MyRoomList){
}
I’m using foreach to cycle through the rooms and check to see which wall would need replaced with a door, I can’t however use this to check every game piece inside of the prefab because it gives me an error saying that there is no IEnumerator for GameObjects.
Maybe I’m just overlooking something very simple, or maybe I’m going about this all the wrong way. Would appreciate any help I could get though as this has been bugging me for awhile.