- Home /
Collecting items when you destroy something?
Hello how would i destroy something and collect whatever prize was in that gameObject? So for example i destroy a tree with my axe and when i destroy it theres a floating item on the ground which is a log and then you collect it. How would i do something like that?
Would it work if i had a onCollisonEnter function and enable the Trigger button?
No, if you enable the trigger button you use OnTriggerEnter.
Answer by GuyTidhar · Jul 04, 2011 at 05:38 AM
You can use the OnDestroy() function to be called from a script attached to the gameObject representing your tree (or any other along the tree hierarchy).
Within the function you should be handling the collection of logs or what ever objects you wish to collect.
The same script could have access to this collection before the destruction takes place.
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnDestroy.html
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
PickUp (Destroy) gameObject one by one 3 Answers
How to insert an object after Destroy(gameObject) 2 Answers
Checking Instantiate/Destroy has been called | Checking number of scene GameObjects 1 Answer
Destroy all GameObjects EXCEPT some... 2 Answers