I would like to expose an enum to something using a System.Object class, but I'm having difficulties putting any enum inside of the class. It seems the only way to use an enum is inside a monobehavior. The following segment of code seems to be invalid in unity and I'm not exactly sure why. If anyone could enlighten me, that would be fantastic. Code (csharp): class CameraData extends System.Object { enum CameraStates { Follow = 0, ChainFollow = 1, SlowRotateAround = 2 } // stuff ... }
Code (csharp): Assets/ Scripts/Managers/CameraData.js(3) error BCE0044: expecting }, found 'enum'. Assets/ Scripts/Managers/CameraData.js(3) error UCE0001: ';' expected. Insert a semicolon at the end. Assets/ Scripts/Managers/CameraData.js(5) error BCE0044: expecting :, found '='.
Enums are defined as separate objects in the same way classes are. You can define them both in the same file, though.
I use code like this all the time. Gives a lovely little drop down selection thingy inside unity. Gotta love it. Code (csharp): public class LanguageController : MonoBehaviour { public enum Language {English, Danish}; public Language language; } Think you might be missing the ; in your code example after the enum declaration.
The ; is actually not necessary after an enum declaration, in the same way that you don't need one after a class declaration. Your example is the same thing as Code (csharp): enum Language {English, Danish} var language : Language; in Javascript, which of course works fine but isn't really the issue here. --Eric