- Home /
why i can not destroy the collider
hello everybody!
i need some help about destroying colliders.
to speed things up i am trying to optimize some functions. i have a bunch of objects that have mesh colliders. mesh colliders work very well for precise selection but when i need to interact with a lot of objects and chech OnTriggerEnter everything slows down terribly.
i tried with boxcollider and it works very fast. when i do need precision selection i would like to turn meshcolliders back on objects to replace the boxcolliders. i tried to track what object i replaced meshcollider with boxcollider and later just loop through the array and to replace boxcollider with meshcollider
here is what i tried:
first i declared the array that will hold the colliders
var boxColliderObjects = new Array();
then in every OnTriggerEnter i have this code:
function OnTriggerEnter(col : Collider){
if(col.GetType() == MeshCollider){ boxColliderObjects.Add(col); var temp : GameObject=col.gameObject; Destroy (col); temp.AddComponent ("BoxCollider");
}
//DO STUFF ON COLLIDERS }
this way i have array that holds all colliders that we changed collider type, so that i can track them and restore them later.
here is the function that should replace box colliders with mesh colliders when i need precision selection
function RestoreMeshColliders(){
for(i=0;i<boxColliderObjects.length;i++){
//Debug.Log(boxColliderObjects[i].name);
var temp : GameObject=boxColliderObjects[i].gameObject;
Destroy (temp.collider);
temp.gameObject.AddComponent ("MeshCollider");
}
}
it replacing mesh with box collider works, but returning back from box to mesh collider does not... any ideas?
thanks!
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
3D text with box collider Android 1 Answer
Copy collider Component type and parameter to a new Object at runtime 0 Answers
Is it possible to skew a box collider? 1 Answer
how to resize box collider? 4 Answers