|
So I'm trying to create a script to make my life a little easier without having to click every single object to add some physical properties. I have everything working except one thing. I am trying to make all of my mesh colliders convex for my selected objects. Here is what I have for code, which comes straight from the unity scripting reference, but it's still not working: @MenuItem ("GameObject/SetConvex") static function setConvex () { Debug.Log ("Set object convex!!"); for (var i = 0; i < Selection.gameObjects.length; i++) { Selection.gameObjects[i].collider.convex = true; } } This comes straight from unity's scripting reference found here: Script Reference But every time I run the script I get an error which says that " 'convex' is not a member of UnityEngine.Collider'. " Anyone got any ideas?
(comments are locked)
|
|
It may be documented that way on the link provided, but documentation isn't always right. I would take the compiler's word for it more so than documentation. In any case, it doesn't seem that the MeshCollider component is by default exposed to the user. I haven't done this myself, but most likely what you'll have to do is ( in c#): If you're using C# and are using MonoDevelop, Intellisense shows that collider does not inherit the member variable convex. Typically when you're programming environment tells you that a variable or component isn't exposed to you through Intellisense, it's usually right and not the documentation. I haven't tested my code, but in theory it should do the trick. EDIT: Also please use the insert code button, it would be very helpful in the future to read your code easier, no matter how short or long it may be.
(comments are locked)
|

So I researched it, and convex is definitely a member of UnityEngine.Collider. Seriously, what the hell Unity? Anyone know a workaround?
This seems to be an Android or iOS issue - code ran fine on WebPlayer but converting platforms yielded this error
convex is not a member of UnityEngine.Collider. It's a member of MeshCollider. A MeshCollider is also a Collider, but a Collider is not necessarily a MeshCollider.
@dannyskim 's answer is correct. UnityScript sometimes tries to figure out the type automatically, but it seems that doesn't work all the time. Also the language has changed a lot since the first release.