Hi,
i just want to refer to my prefabs in a static way.
So i created a class called “Blueprints.cs” and noticed that this seems to need an object Reference.
I built up some singleton like stuff, but then noticed that all the objects are null i trying to create, even if i fill them up in the script.
public class Blueprints : MonoBehaviour
{
// To be preset
public GameObject RightStab;
public GameObject Ball;
// Enemies
public GameObject Wrench;
public static GameObject WrenchStatic; // <<< won't work :-(
}
When i open this script in the inspector,
i can only drag prefabs to the “RightStab” and “Ball” and “Wrench” … the entry “WrenchStatic”
doesn’t appears.
In my ‘main’ script i did the following:
public static Blueprints blueprints;
void Start ()
{
GameObject go = new GameObject();
go.AddComponent<Blueprints>();
}
later in my code, i try to instantiate Gameobjects using this prefab.
But it doesn’t work because it says it was null.
Instantiate(blueprints.RightStab); // Won't Work!
I’m perfectly used to instantiate Prefabs the usual way, but i want to keep all the objects that i may want to spawn in one single class for easier access.
Is there any way to instantiate them in a static way, or via filepath, or … maybe using this workaround i am trying to use here ?
Thanks in advance,
David