Refering to prefabs in yet to be created script

Hello. I currently have the following code:

public class References : MonoBehaviour {

	public GameObject scriptContainerRef;
	static public GameObject scriptContainer;
	
	public GameObject backgroundRef;
	static public GameObject background;
	
	public GameObject wallRef;
	static public GameObject wall;

	void Start () {
		scriptContainer = scriptContainerRef;
		wall = wallRef;
		background = backgroundRef;
	}
}

along with:

What it does is having scriptContainerRef, backgroundRef and wallRef point to a prefabs. then it make the 3 static variables point to these prefabs aswell, since static variables will not show up on the inspector thingy (image). From there scripts that aren’t created by the time i start the game, can create prefabs by refering to them as References.wall etc.

Now, I’m going to add a lot of diffrent objects, and this way is pretty clumsy if you ask me. Is there a simpler way?

It would have been so much easier if static variables would be visible in the inspector list thingy (image), but ofcourse that would create problems when 2 objects with that same script point to 2 diffrent places…

Thanks in advance :slight_smile:

The only other way I can think of doing this is to get a reference to the References object in each object that uses it and then using GetComponent to access the script. You could then just access the instance variables rather than having additional static variables. However, I doubt this is any quicker or easier than what you are currently doing

Very well then, and thanks for letting me know. As for doing the references in each object; the thing is that im working with abstractions unrelated to actual game objects, and thus i only create the script (and attatch it to a gameobject for just that), and that’s why im doing the whole references class in the first place. But yea, thanks for letting me know that im using the easiest way, clumsy or not. :slight_smile: