Can someone explain why I'm getting an error by the "switch" statement, and why it spawns a "Debug" game object when I select Trigger from the menu? Code (csharp): enum nodes{debug,trigger}; function Menu(){ var menu : GenericMenu = new GenericMenu(); menu.AddItem(new GUIContent("Events/Debug/Debug.Log"),false,Nodes,nodes.debug); menu.AddItem(new GUIContent("Conditions/Trigger"),false,Nodes,nodes.trigger); menu.ShowAsContext(); } function Nodes(obj : Object){ Debug.Log ("Selected: " + obj); switch(obj){ case nodes.debug: var debug = new GameObject("Debug"); break; case nodes.trigger: var trigger = new GameObject("Trigger"); break; } }
I'm not too familiar with UnityScript, but it looks like "obj" is being typed as a Unity Object when it should be System.Object. Change Object to object (lowercase O) in this line "function Nodes(obj :Object){"
You may need to cast. You shouldn't be making your parameter "object" anyway if you know it's going to be an enum.. Enumerations are value types and by passing it as "Object" it will be assumed to be a reference type. So, when you pass your enum into the method it will be "boxed" as the type object and then "unboxed" back into your enumeration in your method. This will cause allocations and feed the garbage collector. Instead do: Code (csharp): function Nodes(obj : nodes){ That will also solve your switch issue.