Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Stradigos · Feb 28, 2012 at 06:04 PM · editoroninspectorguiguilabel

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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;

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stradigos · Feb 29, 2012 at 05:53 AM 0
Share

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

avatar image Bunny83 · Feb 29, 2012 at 12:35 PM 0
Share

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?

avatar image Stradigos · Mar 01, 2012 at 02:55 AM 0
Share

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 () {

 

 }

}

avatar image Stradigos · Mar 01, 2012 at 02:56 AM 1
Share

Never$$anonymous$$d! I had to assign it a value, and I also had to make it public!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges