- Home /
Instantiating a class using dragged-in references
I have a class that inherits from MonoBehaviour
and has a public field to hold an image. I want to instantiate it and have the instance store the dragged-in image reference, however my constructor just leaves the field null thinking there is nothing there. When I hit play the editor shows that the field holds the image reference though. How do I tell it to pick up the dragged in reference when instantiating?
How do you instantiate it? You should not use constructors on $$anonymous$$onoBehavior classes.
I was looking for a way to let other scripts modify and use this one and immediately tried making an instance, something like:
public class ClassA : $$anonymous$$onoBehaviour {
public Textre2D image;
void ClassA(){
//stuff that doesn't concern the image
}
}
How can I modify the variables of this script? Should I make the class static?
As I just said, do not use constructors for $$anonymous$$onoBehavior scripts, use Start()
or Awake()
. There's a decent explanation here: http://answers.unity3d.com/questions/32413/using-constructors-in-unity-c.html