How to get my ability to deactivate when it's time then not activate till cooldown is reached C#

Good Morning,

Sorry for the terribly worded question XD but I am making a 2D side scrolling Metroidvania and I have an ability to where when the player hits W they will activate a Game Object that will rest on the player for 45 seconds and shot bullets when they shoot (got that figured out). My problem is I can’t get it to deactivate and I am running in circles trying to figure it out.
Here is the code and related variables, if there is a better way I am all ears

public bool alphaCommand;

    public float alphaCommandTimer;

    public GameObject alphaCommandSpawn;

    public Transform alphaCommandBulletSpawn;

    public float alphaCommandCooldown;

    public bool canAlphaCommand = true;

if(inWolfForm == true && alphaCommand == false && Input.GetKeyDown(KeyCode.W)  && canAlphaCommand == true)
        {
            alphaCommandTimer += Time.deltaTime;

            Debug.Log(alphaCommandTimer);

            alphaCommand = true;

            canAlphaCommand = false;



            if(alphaCommand == true && alphaCommandTimer <= 45)
            {
                alphaCommandSpawn.SetActive(true);
                // Instantiate minion at a transform and make it function like a grunt
                // Actually just make it apart of the player and have it set active and when the player fires a bullet it will fire one as well

                


                
            }
    }

        else if(alphaCommandTimer >= 45)
                {
                    alphaCommandSpawn.SetActive(false);
                    alphaCommand = false;

                    alphaCommandTimer -= Time.deltaTime;

                    if(alphaCommandTimer <= 0 && canAlphaCommand == false)
                    {
                        canAlphaCommand = true;
                    }
                }

Kindly,

Harpoaian

Use a coroutine.

if(inWolfForm == true && alphaCommand == false && Input.GetKeyDown(KeyCode.W)  && canAlphaCommand == true)
         {
             alphaCommandTimer += Time.deltaTime;
 
             Debug.Log(alphaCommandTimer);
 
             alphaCommand = true;
 
             canAlphaCommand = false;
             StartCoroutine(Cannon());
         }

At the moment you call the cannon write the StartCoroutine line, then type in this block of code at the bottom of your script outside of any functions (this requires you to add a public float to your script here called timeActive, you can set that in the inspector to 45, but this will allow you to adjust it later and use on other objects that might have a different cooldown time):

IEnumerator Cannon()
	{
		yield return new WaitForSeconds(timeActive);
        alphaCommand = false;
		yield break;
	}

Let me know if that works.