|
Hey fellas, I have a script that involves a weapon turret. It has two variables, "projectile" and "raycastImpact", both of which you can assign GameObjects. If you set the projectile variable, it will launch the projectile when it fires. If you set the raycastImpact variable, it will create that impact at the hit.point of a raycast. What I want is for the compiler to throw an error if I set both the projectile and the raycastImpact variables. Is there a way to throw a custom error in unity javascript? (I'm assuming there is no better way to organize the variables. There are a couple different variables related to each type of shot; from what I've gathered there is no way to make a group of variables visible in the inspector only if another variable is assigned...) Thanks a ton; you guys are awesome!
(comments are locked)
|
|
You can get the game to throw an exception but you can't make the compiler throw one. Or Or Not sure how you are creating this item - but the best way might be to have 2 static creator functions - one that takes each parameter so you can't pass both.
Aug 04 '12 at 11:13 AM
whydoidoit
Thanks for the replies. But when I try "throw new Exception(..." or "throw new ArgumentException(..." the compiler complains: "Assets/Scripts/GUIManager.js(19,19): BCE0005: Unknown identifier: 'Exception'." whydoidoit -- I'm instantiating the objects within Update() based on if statements.
Aug 05 '12 at 02:26 AM
SergeantBiscuits
change it to "UnityException" throw new UnityException("my custom exception");
Aug 05 '12 at 04:08 AM
Seth Bergman
Sorry, or put System. In front of it.
Aug 05 '12 at 07:23 AM
whydoidoit
Both "UnityException" and "System.Exception" do exactly what I wanted. Thanks fellas!
Aug 05 '12 at 07:28 AM
SergeantBiscuits
(comments are locked)
|

Just a point - I've edited your question to change Java to JavaScript - they are very different languages and Unity doesn't support Java.