Reference to MonoBehaviour?

Anybody know how to get a reference to MonoBehaviour? I’m using C# for an IOS project and doing my homework I learned that using:

MonoBehaviour.useGUILayout = false;

Halves the wear and tear on the OnGUI() function and gives me more RAM to use. Thanks for future help.

If you’re using a normal script, you don’t need any reference. Simply using

useGUILayout = false;

In your Awake or Start blocks will work fine.

Looking at the documentation, though, you need to make sure you’re not using GUI.Window or GUILayout if you want to set this.

Essentially, the way you access variables depends on whether they are ‘instance’ or ‘static’. For the former, each instance of the class (so each script component) can have a different value of the field. For static variables, the value is ‘global’ across the entire program.

What you were trying to do with the syntax above is access useGUILayout as if it were static, which it isn’t. (You can tell 'cause it’s in the ‘Variables’ section of the documentation, as opposed to ‘Static variables’)

What you normally need to do is this case is use a reference to an instance, like this:

GameObject obj = GameObject.Find("My Object"); = "Something else";

In the first line, we find the reference to a GameObject using the static function ‘Find’. In the second, we use this reference to alter the instance variable ‘name’.

But, in your case, we don’t need a reference because we’re already coding from the point of view of that instance.

I hope that clears things up :slight_smile: