- Home /
OnDestroy() object with tag
HAI! I have prefab with tag, for example: "powerup". I need a function that will be called whenever those prefab is destroyed.
Something like OnDestroy, but referring to other prefab.
Would somebody help me?
Thanks.
Comment
Best Answer
Answer by iwaldrop · Jun 03, 2014 at 05:28 AM
You haven't stated your use case, so it's difficult to determine what you mean by other prefab. What other prefab?
Perhaps this will help though:
public delegate void Destroyed(Object o);
public class Powerup : MonoBehaviour
{
public static event Destroyed OnDestroyed;
void OnDestroy()
{
if (OnDestroyed != null)
OnDestroyed(this);
}
}
Javascript doesn't support events, so its impossible. If you must do it in Javascript, the simplest solution is to make a manual call to a static method from OnDestroy() on a script attached to the Prefab.