Disable part of script

How to disable only a part of the script and not entire script? For instance if I wanted to disable a public void Spawner() how would I do that?

I know how to access it, but dont know how to disable “ONLY” Spawner() function within another script. I also know how to disable an entire sript, but no luck in trying to disable only a small part of another script.

So what i need to disable is only “gm2.Spawner()”:

    public class Player : MonoBehaviour 
    {
    private GameManager2D gm2;
    private bool isSpawned;
    
    void Start () 
    	{
    	gm2 = FindObjectOfType<GameManager2D>();
    }
    
     void OnTriggerEnter2D(Collider2D col)
        {
    if (col.CompareTag ("Horse")) {
    
    			if (!isSpawned) {
    				isSpawned = true;
    				gm2.enabled = true;
`                                  gm2.Spawner();`
    }
    }
    
    void OnTriggerExit2D(Collider2D col)
        {
    		isGrounded = false;
    
    		{
    		if (col.CompareTag ("Horse")) {
    			if (isSpawned) {
    			isSpawned = true;
    			Destroy (hor);
    			
    /*
                            //This is what i wish to get DISABLED
                            //gm2.Spawner ();
    
    			//gm2.GetComponent<Spawner>().enabled = false;
                        //THIS ISNT WORKING, but this is what i would like to have
    */
    			Debug.Log ("Destroy HOR PLZ");
    		}
    }
    }

Please if anyone can help me with this problem, because I been struggling with this problem for months now. Thank you in advance!

If I understand, you just need to have an IF statement, with a boolean in its condition that indicates if what’s next is being executed or not.
It is so basic that I think I haven’t undestood the problem.
Hope it helps

This is what i found about this problem. I need someone to look at this and tell me if this is correct. That it is not possible to disable a part of a script or in other words a function.