- Home /
Procedurally Generated Room System...
I am working on a procedurally generated system. In my main script, I have an array of GameObjects called Rooms. I also have an int called AllRooms, and it is said to equal the length of the rooms upon start. However, what I need now is how I can access these rooms, and instantiate one after the other. This has puzzled me for a few hours and I cannot think on how I will bring my way around it. Can anyone help me?
Please consider the fact that all my work is in C#
Thanks in advance!
I cannot tell what your problem is given this description. Posting your code might help. If it is 'just' accessing one game object from another, here is a link:
This is a dupe question it seems... I answered the other one...
This isn't a duplicate. In the first, I asked about how I would place the GameObjects. In this, the question is how I would access GameObjects within an Array. Why did you close my question???
A lot depends on what you're missing from your Question. Are you able to instantiate a single room? If not, I'd recommend getting to that point before looping through and trying to setup a bunch of rooms.
If you can, you should be able to loop through your array and do what you did for that single room, but in each index of the array.
for(int i = 0; i < AllRooms; i++)
{
arrayOfRooms[i] = <Whatever you do to make that single room.>;
}
Answer by Olgo · Apr 01, 2013 at 06:37 PM
I think I may know what you're getting at. I've written a script for a very similar process. Mine is used to create towers or trees from an array of preconstructed gameobjects. See the script and discussion on it here:
http://answers.unity3d.com/questions/415189/how-do-i-get-each-gameobject-to-mind-its-own-busin.html
My preconstructed gameobjects are prefabs with an origin (at the bottom of the tree trunk or tower level) and a spawn point (at the top of the tower room or tree trunk). The script goes through the array of prefabs, finds a piece, instantiates it. It then searches for the spawn point (an empty game object carefully placed in the prefab) and instantiates a new prefab on that gameobject.
The result is each piece of my tower or tree is linked from origin (set in Blender) to spawn point (added in Unity). I imagine you could take a similar approach with your rooms. You could use 2 game objects, one for entrance, one for exit. Make the position of the entrance equal to the position of the previous object's exit and string rooms together like so.
Hope this helps. Comment if you need anymore clarification.
Thanks
Your answer
Follow this Question
Related Questions
Procedural Generation... 2 Answers
A node in a childnode? 1 Answer
Timer help please 1 Answer
Galaxy Procedural Generation 1 Answer
Script Crashing Unity 1 Answer