Hello,
I have a c# class that I reuse for creating simple GUI windows, here’s a strip down version:
class Windows {
public Rect rect;
public bool Show;
public float Width;
public float Height;
public Vector2 start;
public Vector2 end;
public Windows ( float alpha, bool show, Vector2 size, Vector2 positionStart, Vector2 positionEnd){
this.rect = new Rect(positionStart.x, positionStart.y, size.x, size.y);
this.Alpha = alpha;
this.Show = show;
this.Width = size.x;
this.Height = size.y;
this.start = positionStart;
this.end = positionEnd;
}
// other functions
}
Now in some of my other scripts I reference it like this:
private Windows[] Window = new Windows[3];
void Start(){
Window[0] = new Windows (
1.0f,
true,
new Vector2(320,300), // width / height
new Vector2((Screen.width/2)-(320/2), (Screen.height)), // startup x / y
new Vector2((Screen.width/2)-(320/2), (Screen.height)-(300)) // end x / y
);
// more menus
}
void OnGUI(){
Window[0].rect = GUI.Window(0, Window[0].rect, DrawMenu1, "");
// more windows
}
void DrawMenu1(){
// gui buttons, etc
}
While it works 100% no runtime errors, unity is throwing some warnings:
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
In my quest for error/warning free code, I can’t figure out what do about this error. I’m still rather new to unity.
Can someone help me out?