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();
});
}