Question: how to call other script in OnClick?

Hi! I have 2 script, 1 for shop sell item, 1 for open popups.

My question: I want do a check before sell item, if ok then sell item else then call function popup
Here’s my example code:
sell item:

public void MaxE10()
    {
        // do blahblahblah
        if (getCurrentLife < getmaxLife)
        {
            // sell item blahblahblah
        }
        else
        {
            // need call popup function here
        }
   }

popup:

public virtual void WarnFull()
        {
            if ((m_canvas != null) && (warnFullPopup != null))
            {
                var popup = Instantiate(warnFullPopup) as GameObject;
                popup.SetActive(true);
                popup.transform.localScale = Vector3.zero;
                popup.transform.SetParent(m_canvas.transform, false);
                popup.GetComponent<Popup>().Open();
            }
        }

I tried share in popup script

public static PopupOpener share;
void Awake()
        {
            share = this;
        }

but still can’t use PopupOpener.share.WarnFull() in shop script. It say :
“The name `PopupOpener’ does not exist in the current context”
What I should do now?
And thanks :slight_smile:

Is there a PopupOpener class in the popup script? From the error described it sounds like there isn’t.

public class PopupOpener : MonoBehaviour {

    public static PopupOpener share;
    void Awake()
            {
                share = this;
            }

    public virtual void WarnFull()
            {
                if ((m_canvas != null) && (warnFullPopup != null))
                {
                    var popup = Instantiate(warnFullPopup) as GameObject;
                    popup.SetActive(true);
                    popup.transform.localScale = Vector3.zero;
                    popup.transform.SetParent(m_canvas.transform, false);
                    popup.GetComponent<Popup>().Open();
                }
            }
}

yes, it’s

I just stuck what I posted in my editor with a print test in the WarnFull function and called it with PopupOpener.share.WarnFull() and it worked fine. Perhaps check spelling on the class name.


usually I can use share like this. (at upper)
But with this (at bottom), I don’t understand why it’s not work (black color)