I think it should be pretty straightforward, but I have tried a lot of different things and nothing has worked. I have a Game Manager with a script GameManagerScript. Inside that script I have a variable public RoomScript roomToPlaceScript. I want to be able to add roomToPlaceScript to an object after I instantiate it. Kind of like this (but this didn’t work).
GameObject newRoom = (GameObject)Instantiate(roomPrefabsWithoutScripts[nextRoomArrayElement], newRoomPosition, Quaternion.Euler( new Vector3(0f ,-90 * roomToPlaceScript.numRotations, 0f))); newRoom.transform.parent = roomsInDungeonHolder.transform; RoomScript a = newRoom.AddComponent("RoomScript") as RoomScript; a = roomToPlaceScript;
The above partially worked. It attached a RoomScript as a Component, but it only had values for some variables (I’m pretty sure just the variables that were changed in the GameManagerScript).
I have also tried stuff like this
newRoom.AddComponent("roomToPlaceScript") as RoomScript;
but nothing is working. Any help would be greatly appreciated.