GUILayout.button

I am currently running through the videos on Editor Scripting and am trying to replicate an editor script that spawns a prefab and vector3.Zero.

I have this code:

My script that is on the GameObject:

using UnityEngine;
using System.Collections;

public class aScript : MonoBehaviour {

    public GameObject obj;

    public void BuildObject(){
        Instantiate (obj, Vector3.zero, Quaternion.identity);
    }
}

And my script in the Editor folder:

using UnityEngine;
using System.Collections;
using UnityEditor;

public class aScriptEditor : Editor {

    [CustomEditor(typeof(aScript))]
    public override void OnInspectorGUI(){
        DrawDefaultInspector ();

        aScript myScript = (aScript)target;

        if (GUILayout.Button ("Spawn a cube")) {
            myScript.BuildObject();
        }
    }
}

This is what I see in my inspector:

The button does not appear.

The CustomEditor attribute goes on the class, not the method.

1 Like

That kept me busy longer than it should, thank you Thomas.

1 Like