- Home /
Question by
ReynaV · Sep 03, 2014 at 02:32 AM ·
2dgameobjectdestroy
(2d) How can I destroy a gameObject when I pass over it?
When I pass over a specific gameObject, I want to destroy it which is back.
I 'trigger' the object I want disappear and attach the next code to it.
void OnTriggerEnter2D(Collision2D other){
Destroy(gameObject);
}
Comment
Answer by Pyrian · Sep 03, 2014 at 03:27 AM
You didn't actually post a question, but let me post a solution anyway. Don't destroy your object in the trigger - that can have somewhat indeterminate effects on related event calls. Instead, set a flag in the OnTriggerEnter2D, and destroy the object in Update.