- Home /
How to disable hitted collider?[fixed]
I am struggling with a problem that it seems to be impossible to disable the collider but not destroy the gameObject.
if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, hit, distanceToPipe)){
if (hit.collider.gameObject.name == "Pipe"){
hit.collider.gameObject.collider.enabled = false;
}
}
Already thanks.
Ok, first, it looks like you got a negative vote from a member because you didn't format your code. In future, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window. I have formatted this one for you. Please check the code is the same as what you have.
Please watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Answer by Nachtmahr · Apr 04, 2013 at 08:47 PM
if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, hit, distanceToPipe)){
if (hit.collider.gameObject.name == "Pipe"){
Debug.Log("Hit the Pipe");
hit.collider.enabled = false;
}
}
try it
Simoultanus Post ^^ yours is better but we do basicly the same thing Debug the hit.
Answer by AlucardJay · Apr 04, 2013 at 08:45 PM
Let's split things up, do some debugging and see where this is not working for you :
if ( Input.GetMouseButtonDown(0) )
{
if ( Physics.Raycast(ray, hit, distanceToPipe) )
{
// what did the ray hit?
Debug.Log( "ray hit (name) : " + hit.collider.gameObject.name );
if ( hit.collider.gameObject.name == "Pipe" )
{
hit.collider.enabled = false;
}
}
}
check the console for the debug ray hit (name) : [what does it say here? does it say Pipe?]
Your answer
Follow this Question
Related Questions
Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer
need help to destroy game object 1 Answer
how to destroy an object permanently ? 1 Answer
Disabling or Destroying more lagless/ Do colliders and transforms work while disabled? 1 Answer
Making a bullet invinceble 0 Answers