- Home /
How do i delete a gameObject if it enters a box collider using tags
I have tried to make a JavaScript that deletes a certain gameObject when it falls into a box collider.
Function OnTriggerEnter (other : Collider)
{
if (gameObject.tag == "block")
Destroy(block);
}
This is the script that i use.
notice : i already tag the block that i want to destroy with the tag : block.
And in the picture you see i also created another gameObject named, 0-Destroy Platform. It got a Box Collider and "Is Trigger" is selected.(the green square area is the size of the collider) I also know that i have to put the script into this gameObject.
In short : how can i destroy the block when the block hits the box collider.
What did i wrong?
Yes the blocks got a rigedbody. and i know, i mistype it in noteblock but in the script it is with a lower case.
Answer by $$anonymous$$ · Jul 30, 2013 at 11:59 AM
Try this:
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "block")
Destroy(other.gameobject);
}
aha, thanks guys. I just forgot some words :). There is a small error in the script.
gameobject has to be gameObject.
But thanks anyways
Answer by amphoterik · Jul 30, 2013 at 11:58 AM
Ensure that the blocks have a rigidbody. Also, I believe in javascript it is function with a lower case 'f' (not Function).
Also, the script needs to be on the trigger and you need to change the line to:
if (other.gameObject.tag == "block")
Your answer
Follow this Question
Related Questions
OnTriggerEnter not being called 4 Answers
Door Opens Automatically, then it stays open forever. How? 2 Answers
I cant get my animation to trigger. 0 Answers
Move position of box collider using javascript 1 Answer
HELP PLEASE! 3 Answers