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 Vulegend · Sep 18, 2012 at 12:21 PM · listinspector

How to make a drop down list in inspector

Hello , i was searching all over the internet on how to solve this. I was looking in tons of questions/answers and none of them worked for me. I want to make a list in inspector exactly the same as this guy have. I tried with enum listing , like

 public enum List
 {
 item1,
 item2
 };
 public bool Asd;
 
 public class Example {
 Asd = List.item1;
 }

But didn't work out , says i can't assign bool to variable enum. So if anyone can please help i would be grateful.

Comment
Add comment · Show 1
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 Vulegend · Sep 18, 2012 at 09:17 PM 0
Share

Anyone , please help i really need help with this

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Screenhog · Sep 18, 2012 at 09:34 PM

It's pretty easy, although enum's probably not your answer.

You need to make a class, and then reference it. Here's a simple one:

 class Person {
   var name: String;
   var age: int;
   var favoriteFoods: String[];
 }

Then, in any other code, reference it, something like this:

 var teacher: Person; //one person
 var students: Person[]; //a built-in array of people

Note that this is Unityscript, not C#. I believe it's similar in C#, though.

In case you're curious, an enum is for pre-making a list that you'll want to reference later. For instance, something like this:

 enum Gender {Male, Female}
 enum RPSChoice {Rock, Paper, Scissors}

You'd then reference it later:

 var playerGender: Gender;

This would give you the choice in the inspector of Male or Female, and in code, it would be a choice of Gender.Male or Gender.Female.

Comment
Add comment · Show 1 · 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 Vulegend · Sep 19, 2012 at 10:07 AM 0
Share

I need it in C# , can't find it anywhere. I have a script done , 560 lines but all i want is to make the variables looks nice in Editor. Nothing worked , not even the class

avatar image
1

Answer by gminitv · Oct 13, 2013 at 10:32 PM

You want something like this:

 public enum State{
 walking,idle,attacking,eating,sleeping
 }
  
 public class AClass:MonoBehaviour{
 public State current;
 }

Use enumerators and for syntax reference any C# syntax doc or tutorial doesn't need to be Unity3D specific. Using enumerators gives you a drop down in Inspector like you're looking for. This answer came from another source because I wanted to find an easy way to explain in better words than my own and felt the wheel need not be re-invented :)

Link to original post on answers.unity3d.com/questions with this solution

PS: I am not fluent in C# language but you may not be able to store a boolean as an enumerator. In that case it would be a "type miss-match" error most likely because the Boolean Object may not be able to be stored as an Enumerator Object. In context imagine you have a list of cars and ONLY cars are allowed to be part of the list. If you say you want to add a Banana (which is a fruit not a car) to the list of Cars with this same logic you wont be able to. Only cars are allowed in the cars list (cars object no banana objects or other object types allowed) This is the same case when trying to store and integer as a string or a string as an integer. Usually there is some form of method or function or something you can "call" or reference to convert objects of different types. Usually this looks like this : String number = Number.getValueOf.toString() (no particular syntax just explaining in a code type form) You could Google search for "How to convert a boolean to enumerator object" or "how to store a boolean as an enumerator" or possibly just google search the EXACT error that your compiler is giving you about why it will not allow you to store the boolean as an enumerator.

I would imagine alternatively you could create a custom class that does exactly this. converts true/false yes/no booleans into an enumerator. Just create a class that has a method/function like this: convertENUMS(String s, Int i, Enum e, Boolean B); and then call this method when you need to store the boolean as enum or any other conversion you may need. If you convert the boolean to a string first called "yes or no" or maybe "hair, nohair" or "Gravity, NoGravity" or "Hit,Miss" then just do simple if/then (if ( ourstring != "hit" ) then { print('we have a MISS!') }

Comment
Add comment · 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

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Custom Editor - Show variable if bool is true in class list 1 Answer

How can I make multiple of entry for arraylist in inspector 2 Answers

Is it possible to drag/drop/increment into editor array? 1 Answer

Name for list item selection/movement bar? 0 Answers


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