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?
Worked like a charm! Thank you.
– Mmrw