Help with if statements

Okay. So I want to make it where you have to press the button more than once for each time. When I run this code if I have more than 10 levelpoints it takes 10 away and doesn’t allow my weapons to switch properly. Here is my code for the upgrades:

function Update(){
    if (Input.GetButtonDown("Fire1")){
    Shoot();
    }
    if(Input.GetKeyUp("q"))
{
	print("You pressed q");
	 Debug.DrawRay(transform.position, transform.forward * 10);
		if(Physics.Raycast(transform.position,transform.forward,hit,5))
		{
		print("The Raycast is working, and hit: " + hit.collider.gameObject);
		 Debug.DrawRay(transform.position, transform.forward * 5.0);
			if (hit.collider.gameObject.CompareTag("Weapon Upgrade"))
			{
			print("It knows that the weapon is a Weapon Upgrade");
				if (Score.levelPoints > 0 && weaponLevel == 1)
				{
					print("It is applying the upgrade.");
					Score.levelPoints -= weaponLevel;
					weaponLevel += 1;
					GunSwitch.gunLevel += 1;
					playerDamage += 50;
				}
				if (Score.levelPoints > 1 && weaponLevel == 2)
				{
					print("It is applying the upgrade.");
					Score.levelPoints -= weaponLevel;
					weaponLevel += 1;
					GunSwitch.gunLevel += 1;
					playerDamage += 50;
				}
				if (Score.levelPoints > 2 && weaponLevel == 3)
				{
					print("It is applying the upgrade.");
					Score.levelPoints -= weaponLevel;
					weaponLevel += 1;
					GunSwitch.gunLevel += 1;
					playerDamage += 50;
				}
				if (Score.levelPoints > 3 && weaponLevel == 4)
				{
					print("It is applying the upgrade.");
					Score.levelPoints -= weaponLevel;
					weaponLevel += 1;
					GunSwitch.gunLevel += 1;
					playerDamage += 50;
				}
			}
		}
}

This is my code for my weapon switching:

var gun1: GameObject;
var gun2: GameObject;
var gun3: GameObject;
var gun4: GameObject;
var gun5: GameObject;
static var gunLevel: int = 0;

function Start () {
	var gun : GameObject = Instantiate(gun1, transform.position, transform.rotation);
	gun.transform.parent = this.transform;
}

function Update () {
	if (gunLevel == 1)
	{
		Destroy(gameObject.FindWithTag("Gun"));
		gunLevel += 1;
		var guntwo : GameObject = Instantiate(gun2, transform.position, transform.rotation);
		guntwo.transform.Rotate (0, 180, 0);
		guntwo.transform.parent = this.transform;
	}
	
	if (gunLevel == 3)
	{
		Destroy(gameObject.FindWithTag("Gun"));
		gunLevel += 1;
		var gunthree : GameObject = Instantiate(gun3, transform.position, transform.rotation);
		gunthree.transform.parent = this.transform;
	}
	if (gunLevel == 5)
	{
		Destroy(gameObject.FindWithTag("Gun"));
		gunLevel += 1;
		var gunfour : GameObject = Instantiate(gun4, transform.position, transform.rotation);
		gunfour.transform.parent = this.transform;
	}
		if (gunLevel == 7)
	{
		Destroy(gameObject.FindWithTag("Gun"));
		gunLevel += 1;
		var gunfive : GameObject = Instantiate(gun5, transform.position, transform.rotation);
		gunfive.transform.Rotate (0, 180, 0);
		gunfive.transform.parent = this.transform;
	}


}

How would I go about fixing this so that you have to press q for each upgrade instead of just once?

It’s because you’re falling through each if statement, you’re defining them as separate if statement block instead of a grouping them with else if statement blocks and hitting each one.

Example:
Score.levelPoints = 10
weaponLevel = 1

Lets consider your code with those varables.

if (Score.levelPoints > 0 && weaponLevel == 1)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}

// now weaponLevel is 2 and Score.levelPoints = 9

if (Score.levelPoints > 1 && weaponLevel == 2)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}

// now weaponLevel is 3 and Score.levelPoints = 7

if (Score.levelPoints > 2 && weaponLevel == 3)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}

// now weaponLevel is 4 and Score.levelPoints = 4

if (Score.levelPoints > 3 && weaponLevel == 4)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}

// now weaponLevel is 5 and Score.levelPoints = 0

This was executed in one invocation and now you’re pooched.

a better way:

if (Score.levelPoints > 0 && weaponLevel == 1)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}
else if (Score.levelPoints > 1 && weaponLevel == 2)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}
else if (Score.levelPoints > 2 && weaponLevel == 3)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}
else if (Score.levelPoints > 3 && weaponLevel == 4)
{
	print("It is applying the upgrade.");
	Score.levelPoints -= weaponLevel;
	weaponLevel += 1;
	GunSwitch.gunLevel += 1;
	playerDamage += 50;
}

// In the above case you can only hit one when invoked(hitting q) or techincally none if the if statement is not met, this is generally when you might just end with an else as a default.

You will need to apply the same logic to your code for switching weapons, you increase the weaponLevel if your update function in that script and since the following if statement may pickup and increase the weaponlevel again, you fall prey to your own code.

You may want to take a look at switch/case statements for simple integer based logic.