I'm having trouble with grids and instantiating arrays of prefabs.

Hey people,

I’m a Noob, i’ll admit it but i’m not ashamed to ask for help when I need it.

So my problem is threefold.I’m using C#

I’m trying to create a game grid where prefabs can be instantiated and then then rotated (by 90, 180, or 270 degrees), or swapped out at runtime.

the purpose of this is to have a game where we start with one tile with either 0, 1, 2, 3, or 4 exits on the sides of a plane ( think doors to a room) which can be rotated by the player and then set (cannot be rotated anymore).

After this i need to work out how to have the grid know where the doors are and instantiate rooms where the first room had doors but not where they didn’t. I have a prefab of a room that rotates when the boolean set = false and cannot be rotated further when set = true.

and the third problem i can’t seem to figure out is how to leap the rotation of the prefab, at the moment it just jumps. i tried rotate towards by adding an unrendered plane with a connected empty transform to control the rotation but then when i added it to the prefab its rotation is driven by the room tile and so one key press equals constant rotation.

any help would be appreciated and if you need me to be clearer ill try!

my lack of knowledge also means i’m not even sure if this is possible the way i have conceived so if i’m going about it the wrong way just say so and i’ll rethink my strategy.

thanks in advance
Simon
England
UK
The World

First: use a two-dimensional array for the rooms if you know max width and height (also maybe to start with)

Second: have scripts attached holding eg bools for all four directions of your rooms. Check them on instantiation and spawn a room in the direction of the doors. But this will get very fast very complicated. Is there already a room? Is there already NO door, so a door is useless…

Third: lerp can interpolate vectors. Interpolate from eg vector3.right to vector3.up and set the rooms right vector to it, it should rotate. Or rotate by tiny amounts around the desired axis of a room (vector3.up?)

Thats some ideas I can provide.