Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor and Script

Discussion in 'Scripting' started by iagoccampos, Dec 14, 2014.

  1. iagoccampos

    iagoccampos

    Joined:
    Aug 2, 2014
    Posts:
    10
    Hey guys, I like to solve some doubts.

    I have a script, called RandomRoom, and that have three enums called RoomType, RoomEntrance and RoomExit. I like to know if there is a way to choose an enum and other options enum appear in the inspector
     
    Last edited: Dec 14, 2014
  2. thepenguinmaster

    thepenguinmaster

    Joined:
    May 22, 2013
    Posts:
    29
    An enumeration can surely appear in teh inspector.

    You shoudl ahve a gameobject that is being inspected. In this object, attach the script that holds the enumeration (the room script I suppose). You will want to have somethign like this:

    Public RoomType MyRoomType = RoomType.whatever;
    Public RoomEntrance MyRoomEntrance = RoomEntrance .whatever;
    etc..

    When you click on your game object and look in the inspector, you should see a property called My Room Entrance and next to it there will be a drop down with your values. I use this quite often as it is a nice clean way to give the user options.

    If you do this and you do not see the value in the inspector, make sure your variable is marked as public, and if there is still a problem, add [Serializable] above your enumeration.

    If [Serializable] is showing a reference error, you can right click the text and then select resolve, and then click the first option. It will automatically add the using statment for you.

    If you still run into trouble, post your script and I would be happy to help.