Greetings all,
I have been busy the past few months tinkering with all different parts of unity, and after having had everything from terrain, materials, modeling, uv-mapping, lightmapping and such it was finally time to move on to scripting.
I used to be quite familiar with C#, and managed to clear off a quite thick layer of dust which was sitting on top, nevertheless i stumbled into a problem i couldn’t get around.
Please let my try to explain this situation a little more clearly:
In my current testing scene i am experimenting with my own ways of procedural level generation, thanks to tile-selection.
In an attempt to accomplish this i currently have only two objects in the scene which contain scripts of which i want to be able to read out one and another’s values.
One is named “LevelGen”, containing a script named “Generation”.
The other is named “TileSets”, containing a script named “Tiles”.
Now, so far, so good.
In the Generation script, unity will at random generate a certain set of tiles and depending on surrounding tiles excisting or not, it should be able to judge what type of tile to select (The intention is to end up with a 3d level).
In this way of setting up i liked using “TileSets”, in the “Tiles” Script i have as an example the following part of script:
extremely simplified Tiles script below:
public class Tiles : MonoBehaviour {
public Transform HallwayXPrefab;
public Transform HallwayZPrefab;
public Transform CrossSectionPrefab;
}
public class HallwayX : Tiles {
static string Direction = "X";
static int Length = 2;
}
public class HallwayZ : Tiles {
static string Direction = "Z";
static int Length = 2;
}
public class CrossSection : Tiles{
static string Direction = "C";
static int Length = 2;
}
Now my questions i can’t find the answer to:
How could i manage to make the currently public Transform variables into Static ones?
In the end i would like my script used in LevelGen(Generation.cs) to be able to browse through a tile’s attributes by the following tree structure:
Tiles.TileType.Attribute, eg;
Tiles.HallwayX.Direction should return X (and it does, luckily)
so Tiles.HallwayX.Prefab should then in turn return a reference to the asset i linked through the inspector right now on this script (so i could use, ofcourse this reference to actually spawn the asset.)
Clearly i’m missing something, and clearly these Transform variables can’t be marked as Static in the beginning, since then i can’t any longer bind them using the inspector (drat!
)
I hope the answer is so simple i should be able to hit myself in shame even ![]()
Thanks in advance to anyone who’s willing to help me out!