- Home /
Disabling Mesh renderer on collision
I am making a car game. I have seperated the parts of the mesh, as in the hood, the roof all are separate meshes and child of the main object. I have applied mesh collider on each one of them. I want that when the mesh collides, its mesh renderer dissapears and the mesh renderer of the deformed mesh becomes visible(which is disabled by default). Here is the code for it:
var broken : Transform; //the new deformed mesh
function OnCollisionEnter(){
gameObject.renderer.enabled = false;
broken.renderer.enabled = true;
}
I attached this code to the part, but is doesnt work! Also, when i apply the same code to any other cube which is not a chold of the car, and when the cube collides with the hood, the hood deforems perfectly as expected! but when i make that cube a child of the car, then again it doesnt work... :(
Someone pls help, this is an integral part of my game!!
Answer by SkaredCreations · Mar 22, 2014 at 05:40 PM
So it seems an issue with your car, may be your collider is not being hit and this could be due to another bigger collider in the hierarchy of your car. You could try to disable all the colliders of your car and its children and enable only the one of your hood and see what happens (or check if any of the scripts attached to your car or children is disabling colliders). Without more information on your car setup it's pretty difficult to understand the reason, may be you can add screenshots.
nope, the only colliders on the car are the mesh colliders...I added a screenshot so you can see,.................................
[1]: /storage/temp/24067-car.png