How do I keep an Int from resetting?

In the upgrade to the space shooter tutorial I am working on I have added a weapon upgrade. This currently gives the player 3 levels of firepower. Collecting the upgrade works great but when the player hits the max upgrade level and then collects the weapon upgrade again the weapon resets to the lowest level. Basically it goes:

firepower = 3, collect upgrade, firepower = 0

Here is the script I’m using:

	void OnTriggerEnter (Collider other) {
		
		if (other.tag == "Blast") {

			firepower = (firepower +1 ) % 3;

			Destroy(other.gameObject);

		}
	}

	void Update ()
	{
		if (Input.GetButton ("Fire1") && Time.time > nextFire) {
			nextFire = Time.time + fireRate;

			if (firepower == 0) {
			Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
			audio.Play ();
			}

			if (firepower == 1) {
				Instantiate (duoshot, duoSpawn.position, duoSpawn.rotation);
				audio.Play ();
			}

			if (firepower == 2) {
				Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
				Instantiate (duoshot, duoSpawn.position, duoSpawn.rotation);
				audio.Play ();
			}
		}
	}

How do I keep my weapon from downgrading when the player collects a power up and the weapon is already at maximum fire power?

Because when firepower = 2 and you add one and use modulo, the reminder is 0 and firepower is equal to zero as stated in your OnTriggerEnter.

So you can constrain it:

void OnTriggerEnter (Collider other) {
	if (other.tag == "Blast") {
		// if the firepower is either 0 or 1 then it will do it's work, otherwise it's max.
		if (firepower < 2)
			firepower = (firepower +1 ) % 3;
			
		Destroy(other.gameObject);
	}
}