- Home /
The question is answered, right answer was accepted
Need help to destroy an object.
So the problem is that i need some help to destroy an object. am currently using this code;
var Control_box;
var Roadblock : Transform;
function OnControllerColliderHit (hit:ControllerColliderHit)
{
// if the player hits a control box
if (hit.gameObject.tag == "Control Box 1")
{
Destroy(gameObject.Find("road block 1"));
}}
the point is that when you as a player hit a control box, a door will open on the other side of the room. but as of now i run into the control box and nothing happens.
Answer by Dave-Carlile · Apr 30, 2013 at 01:40 PM
Add some calls to Debug.Log
. One just inside the OnControllerColliderHit
function to make sure it's being called. Make sure you log hit.gameObject.tag
so you can verify that the tag is what you expect it to be. Also add one inside the if
so you can make sure that code is being called. And finally, move the gameObject.Find("road block 1")
outside of the Destroy
call and assign it to a variable. That will let you add a log message to determine if it's finding that object.