So I’ve gotten the “the thing you want to instantiate is null error” one too many times and I’m stuck. I already know that if I go into the Unity GUI and go and drag the right object type into the public variable i create, voila it works…
What I don’t know is why?? Why can’t I just make it a private variable and instantiate the object using code? There has to be a way to do this, but I can’t figure it out.
Why doesn’t this work without the whole drag and drop routine…BUT it does work if i drag a WackAMole onto the public WackAMole object in my Annoying script…
public class WackAMole : MonoBehaviour {
public string FMe = "go jump off a bridge"
}
public class Annoying: MonoBehaviour {
public WackAMole wacky;
private void Start () {
wacky = (WackAMole)Instantiate(wacky);
}
}