- Home /
OnInspectorGUI - GUILayout.Label doesn't exist?
The compiler is telling me that "The name 'GUILayout' does not exist in the current context." I don't see how that can be true, especially since I'm following a video tutorial of it. Did something change, or what I am I doing wrong?
using UnityEditor;
[CustomEditor (typeof (playerSpawnScript))] public class PlayerSpawnEditor : Editor { private SerializedObject m_Object; private SerializedProperty m_Speed;
public void OnEnable ()
{
m_Object = new SerializedObject (target);
m_Speed = m_Object.FindProperty("speed");
}
public override void OnInspectorGUI ()
{
m_Object.Update();
GUILayout.Label("Player Spawn", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_Speed);
m_Object.ApplyModifiedProperties();
}
}
I've looked up the API references and according to what it says I have everything correct, yet this error! Help!
Answer by Bunny83 · Feb 28, 2012 at 06:05 PM
Ever heared of namespaces? ;)
Use just use the UnityEditor namespace which just contains the Unity editor specific addons.
All you need to do is also include the UnityEngine namespace:
using UnityEditor;
using UnityEngine;
Thanks! Any chance you could tell me why my Inspector is suddenly looking like this now? I added in the namespaces, but the source is still the same as above. http://screencast.com/t/zdROYdUB
Well i can't say for sure without seeing your "playerSpawnScript", but i guess there is no public variable called "speed" or it's a not supported type.
Don't you get some errors?
Shouldn't this work? Or do I have to declare the int in a certain so it can be read by the serialized property in the editor script?
using UnityEngine;
using System.Collections;
public class playerSpawnScript : $$anonymous$$onoBehaviour {
int speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Never$$anonymous$$d! I had to assign it a value, and I also had to make it public!
Your answer
Follow this Question
Related Questions
Problem keeping List variables saved when triggering play button 2 Answers
Type casting SerializedProperty.objectReferenceValue doesn't work? 3 Answers
Add trasform to list using editor gui. 1 Answer
BCE0019 errors in Custom Editor script 1 Answer
OnInspectorGUI() Getting Control 2's position in a group with only 2 controls when doing repaint 1 Answer