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.
2 Answers
2
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?]
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
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
– AlucardJay