- Home /
Question by
MintyAnt · Oct 05, 2012 at 12:00 AM ·
c#editorinheritancepublic
Exposing variables in unity based on an enum
Hello,
In unity I am scripting in C#. In it I am creating some inherited classes. These classes have an enum attached to it that marks which class it is.
enum vType
{
None = 0,
Car,
Boat
}
class Vehicle {
protected vType type;
}
class Car : Vehicle {
public brakeSpeed;
public Car() { type = vType.Car; }
}
class Boat: Vehicle {
public numMotors;
public Car() { type = vType.Boat; }
}
Finally, a MonoBehaviour with a member of Vehicle.
public aScript : MonoBehaviour {
public vType[] vehicles
}
Unity is pretty awesome, because that enum array, when exposed to the editor, can be set to one of the enums I defined here (none, boat, car, etc...) However, Boat and Car have two exposed members.
If the user chooses "3" for the number of vehicles, and the first one as "car", I want Unity to then show the exposed variables and let them be settable somehow.
Now, this might not be the exact implementation, but I think you get what i'm shooting for.
Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613081910im_/https://answers.unity.com/themes/thub/images/avi.jpg)