EditorGuiLayout - Objectfield

Hello, I have an editorscript and I want to have a togglegroup with an objectfield in it.

First Question: Is it possible to just use a public variable in my normal script or do I HAVE to make an objectfield in the editorscript.

Second: How do I make an objectfield. I have seen the reference: Unity - Scripting API: EditorGUILayout.ObjectField

but it doesn’t work. Now when i try it myself I get stuck at the GUIlayoutoptions parameter.

Anyone got an example?

var t = target as DayOrNight;
		
		if(true) {
			t.BlendValue = EditorGUILayout.FloatField("Blend Value", t.BlendValue);		
		}
	
		t.DayColor = EditorGUILayout.ColorField("Day Color", t.DayColor);
		t.NightColor = EditorGUILayout.ColorField("Night Color", t.NightColor);
		
		groupEnabled = EditorGUILayout.BeginToggleGroup("Has Light", groupEnabled);
			t.rotatingLight = EditorGUILayout.ObjectField("light source", t.rotatingLight, typeof(Light),false) as Light;
		EditorGUILayout.EndToggleGroup();
		
		if(GUI.changed) {
			EditorUtility.SetDirty(t);
		}

First) I suppose you mean if you can use a public variable and have it automatically shown in the default Inspector. If so, the answer is yes. Actually, each time you have a public Transform that is shown in the Inspector, that is an ObjectField.

Second) let’s say you have a serializable Transform you want to assign within a custom Inspector, you do it like this:

myTransform = EditorGUILayout.ObjectField("My Label", myTransform, typeof(Transform), false) as Transform;

The “false” parameter is the one that determines if you want users to be able to assign scene/hierarchy objects or only assets from the project panel.