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.
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
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!’) }