So I’m writing my own container classes for GUI labels, buttons, etc to make my life a lot easier. I have a container class for a button which has a base constructor of…
public PsyUI_Button(float xPos, float yPos, float width, float height, string text)
{
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
this.text = text;
}
This is all fine and dandy but, of course, it appears that I can only pass values to the base constructor by using the ‘new’ keyword.
But because my classes derive from MonoBehaviours, the compiler will throw up the error, “You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed”.
So how do I instantiate an object derived from MonoBehaviours and pass in values for the base constructor at the same time?
I don’t want store the object into a variable and manually change the values line by line because that would lead to a silly amount of lines once I instantiate lots of objects. :\
promoting my related question: http://answers.unity3d.com/questions/445444/add-component-in-one-line-with-parameters.html
– cregox