- Home /
OnTriggerEnter is not running! Need help with collision.
I am making jumping game and I have a problem.(I am using Unity 4 and 2D Toolkit.) I have a 3 sprite in scene.First layer, second shaman(main character), third gold. I want to collision shaman and gold.When shaman touched gold, I want to destroy gold.
Here is the code:
void OnTriggerEnter(Collider collision) { Destroy(collision.gameObject); if (collision.gameObject.tag == "goldshaman") { Destroy(gameObject); } }
I made a shaman tag is goldshaman and shaman and gold is own to sphere collider. Also is trigger marked.(gold and shaman). Shaman and gold is same z axis.Gold is moving and touched shaman but shaman is not destroy.
Simply can't work why?
Please help guys.
Answer by gregzo · Jul 27, 2013 at 01:18 PM
Hi teteye,
I was just pointed to this page of the documentation yesterday, scroll at the bottom, there is a chart showing what reacts to what. Probably you need a rigidbody on your shaman.
Hi gregzo, first of all thank you for answer.
Sorry, I add a rigidbody shaman after shaman is drop the scene. I think wrong the question.
I only want to gold touched the shaman after gold is destroy but shaman stop the screen.(not destroy)
Answer by teteye · Jul 28, 2013 at 11:07 AM
I add a Rigidboy(use gravity and is kinematic) on Gold and Shaman. After solved a problem. Thank you gregzo!
Your answer
Follow this Question
Related Questions
Something wrong with destroying script 0 Answers
Destroying object when player walks over it 1 Answer
Trigger Spawning? 1 Answer
Can't click gameobject when over another trigger? 1 Answer
Destroy the gameObject after seconds when not hit. 0 Answers