Attempting to Increase Ammo by Killing Enemy

So I have a system in place that limits the amount of bullets the player has access to at a time, with the ammo recharging over time. This is mostly working, however I wanted to make it so you also get ammo back when killing an enemy. I’ve tried looking around but haven’t really found how to make it work.

I have a bool variable in the enemy’s script called “didDie” that I set to true when their health reaches 0, along with a function called “Die()” that destroys the enemy game object. I’ve tried to reference and check the function but I found that it would be better to check the bool. So now I’m trying to check this bool and then give ammo back if the player has less than max ammo, but when I run it with the code that is currently commented out, it simply increases the ammo continuously. Any insight to this problem and/or different solutions would be much appreciated.

Enemy enemy; 

void Start()
{
    enemy = GameObject.FindGameObjectWithTag("Enemy").GetComponent<Enemy>();
}

void Update()
        {
            //Shoot with a cooldown interval between shots
            if (timeBtwShots <= 0)
            {
                if (Input.GetButtonDown("Fire1") && shots >= 1)
                {
                    Shoot();
                    timeBtwShots = startTimeBtwShots;
                }
            }
            else
            {
                timeBtwShots -= Time.deltaTime;
            }
    
            if (shots <= maxShots)
            {
                shots += shotIncrease * Time.deltaTime;
            }
            //Trying to get shots back from enemy death
            //else if (shots <= maxShots && enemy.didDie = true)
            //{
            //    shots += 1;
            //}
            
    
        }

For those following this question, this was a simple syntactical error on my part. I put the function in its own “if” statement so that it can happen concurrently with the passive ammo increase, and “enemy.didDie = true” does not compare “didDie” with being true.

It should have been

//Trying to get shots back from enemy death if (shots <= maxShots && enemy.didDie == true) { shots += 1; }

The reference to the enemy script and its bool was correct. Now, the math is incorrect as it still has some bugs that increase “shots” past “maxShots”, but I’ll continue to mess with it until it works.