Lost in references (C#)

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! :stuck_out_tongue: )

I hope the answer is so simple i should be able to hit myself in shame even :stuck_out_tongue:
Thanks in advance to anyone who’s willing to help me out!

Properties do not need to be marked as static for them to appear in the inspector…i hope i read that right. plus that would be horrible if that class was used more then once, if they had static transforms… unless you wanted things to move and such in the same way(crowd).

Ehm, not quite.

The Inspector part works fine

Basically I would like the Transforms defined in Tiles.cs to be stored as statics.
i.e. The asset bound to “HallwayXPrefab” would be entered to the value of “Tiles.HallwayX.Prefab” so i could easily use this variable in my other script (Generation.cs) which is attached to LevelGen. But when i try to call this when using

public class HallwayX : Tiles {
static string Direction = "X";
static int Length = 2;
static int Prefab = Tiles(HallwayXPrefab);

it does not seem to work.

I’m giving up for the night… The Hierarchy is as follows:

LevelGen (Script:Generation.cs)
TileSets (Script:Tiles.cs)

Generation.cs:

using UnityEngine;
using System.Collections;

public class Generation : MonoBehaviour {
	public Transform prefab;
	public int randomsteps;
	public UnityEngine.Transform HallwayXPrefab;
	public UnityEngine.Transform HallwayZPrefab;
	public UnityEngine.Transform HallwayCSPrefab;
	
	private Vector3 nextPosition;
	void Start () {
		nextPosition = transform.localPosition;
		for(int i = 0; i < randomsteps; i++){
			Transform o = (Transform)Instantiate(HallwayXPrefab);
			o.localPosition = nextPosition;
			nextPosition.x += 2;}
}
	void Update () {
		HallwayXPrefab = transform.Find ("TileSets").GetComponent(new Tiles(HallwayX.Prefab));
		HallwayZPrefab = Tiles.print(HallwayZ.Prefab);	
}
}

Tiles.cs

using UnityEngine;
using System.Collections;

// Tree format
// Tiles.TileType.Attribute

public class Tiles : MonoBehaviour {
	public Transform HallwayXPrefab;
	public Transform HallwayZPrefab;
	public Transform HallwaySqPrefab;
}


public class HallwayX : Tiles {
	static string Direction = "X";
	static int Length = 2;
	static UnityEngine.Transform Prefab = null ;
	void Update () {
	HallwayX.Prefab = HallwayXPrefab;}
}

public class HallwayZ : Tiles {
	static string Direction = "Z";
	static int Length = 2;
	static UnityEngine.Transform Prefab = null ;
	void Update () {
	HallwayZ.Prefab = HallwayXPrefab;}
}


public class HallwaySq : Tiles{
	static string Direction = "SQ";
	static int Length = 2;
	static UnityEngine.Transform Prefab = null ;
	void Update () {
	HallwaySq.Prefab = HallwaySqPrefab;}
}

Currently only the last two lines in Generation.cs generate errors (in both cases “‘Hallway*.Prefab’ is Inaccessible due to its protection level” That’s basically the furthest i got in trying to pull the variable in :confused: