- Home /
Question by
dragondragoon4 · Apr 01, 2020 at 02:41 AM ·
destroygameobjectaction
Destroy action deleted the original gameObject
Hello. I'm send an action from A gameObject to B gameObject. When the action was executed, it deleted A gameObject rather than B gameObject. I know it is referencing problem. I've tried using GameObject.Find to correctly delete B gameObject but it was lowering the performance. Any other way to solve this problem? Thank you for your help.
public void PopUpNotify(string message)
{
Action action = () =>
{
Destroy(gameObject);
};
MessageManager.Instance.CreatePopUpNotify(message, action);
}
public void CreatePopUpNotify(string message, Action action)
{
messageText.text = message;
transform.SetParent(canvas);
transform.localScale = Vector3.one;
_bttn.onClick.AddListener(() =>
{
action();
});
}
Comment
Answer by LucasIsMuyIntelligent · Apr 01, 2020 at 09:20 AM
@dragondragoon4 Did you try "Destroy(other.gameObject)"?
Thanks for you reply, but A gameObject and B gameObject are not colliding each other. They are UI element and empty gameobject.
Your answer
![](https://koobas.hobune.stream/wayback/20220612230225im_/https://answers.unity.com/themes/thub/images/avi.jpg)