- Home /
Editor Scripting Question
Trying to make a simple Editor macro which would:
1) Add a Rigidbody.
2) Add a BoxCollider.
3) Enable "isTrigger" on the BoxCollider.
I've got as far as the first two steps but stuck on the third - flexed my Google-fu and forum searched but came up empty.
Here's what I have so far:
import UnityEditor;
@MenuItem ("Window/Rigidbody and BoxCollider")
static function AddRigidBodyAndBoxCollider() {
EditorApplication.ExecuteMenuItem("Component/Physics/Rigidbody");
EditorApplication.ExecuteMenuItem("Component/Physics/Box Collider");
}
Any ideas are appreciated!
Awesome - great answer as usual $$anonymous$$ike. Am also a huge fan of unitygems.com - really opened my eyes on state machines. I encourage anyone looking to take the next step to check out $$anonymous$$ike's contributions.
Answer by whydoidoit · Apr 12, 2013 at 02:51 PM
Try this:
if(Selection.activeGameObject)
{
var rigidBody = Selection.activeGameObject.AddComponent(Rigidbody);
var boxCollider = Selection.activeGameObject.AddComponent(BoxCollider);
boxCollider.isTrigger = true;
}
Your answer
Follow this Question
Related Questions
Changes to Object made in custom Editor Window don't persist 0 Answers
Editor menus are invisible 1 Answer
Is there a way to avoid the Animation window drop-down menu with a selected Animator? 0 Answers
Is it possible to detect drag and drop in hierachy window? 0 Answers
How do I create a new object in the Editor as a child of another object? 1 Answer