- Home /
on trigger enter
In my game i have ten ball hanging in the air which is tagged as ball.I have a cube in the ground.Here i am using on trigger enter my problem is when each ball hit the cube i want to destroy the particular falling ball on the cube.I want to destroy the particular ball which is on trigger with cube which is placed in ground and want the rest of hanging balls to be in there position with out destroy.But any ball can fall on this cube according to that i want to destroy the ball.
Answer by aldonaletto · Jul 30, 2011 at 11:08 AM
Attach this script to the cube (or add this code to the cube script, if any):
function OnTriggerEnter(thing: Collider){ if (thing.tag == "ball"){ Destroy(thing.gameObject); } }The ball which touched the trigger will be killed. For this to work, the ball must be tagged "ball" (tags are case sensitive!) and have a collider.
No problem: when OnTriggerEnter is called, the parameter thing identifies only the ball which touched the trigger (it's the ball's collider, which allows direct access to the most important object variables, like tag, gameObject, transform etc.). Only this particular ball will be destroyed - all the others will remain alive and kicking (until they touch the mortal trigger, of course).
Your answer
Follow this Question
Related Questions
OnTriggerExit() help 0 Answers
i need detailed instructions... cue texture 1 Answer
fetching a value 1 Answer
OnTriggerEnter problem 3 Answers