Posts Tagged meshcollider
Unity automatic MeshCollider generation
Posted by whydoidoit in Project With Code on March 22, 2012
When ever I get a model that has many sub elements, but no standard mesh colliders I use the wizard listed here to automatically generate them. Thought it might come in useful to others…
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Linq;
public class AddColliders : ScriptableWizard {
[MenuItem("Wizards/Add Mesh Colliders")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<AddColliders>("Add mesh colliders", "Add Colliders");
}
void OnWizardCreate()
{
if(UnityEditor.Selection.activeGameObject != null)
{
foreach(var c in UnityEditor.Selection.activeGameObject.GetComponentsInChildren<MeshRenderer>().Cast<MeshRenderer>().
Where(mr=>mr.GetComponent<MeshCollider>()==null))
{
c.gameObject.AddComponent(typeof(MeshCollider));
}
}
}
void OnWizardUpdate()
{
helpString = "Add mesh colliders to all items that have a mesh renderer";
}
}

Mike Talbot is Chief Visionary of 3radical. He started his career as a game programmer working for UbiSoft and Electronic Arts among others. Currently he is programming mobile applications in Javascript, HTML5 and ASP.NET.
email: 