- Home /
 
How to Fix This?
I'm creating a fps game and i have a list of weapons that the player can switch between but for some reason gun number 1 does not work. gun 0 works as well as gun 2 and up it's really bugging me here is a copy of the code.
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Gun_Switch : MonoBehaviour {
     
     public PerformAllAttacks script;
     public Gun_List script2;
     
     
     
     
     // Update is called once per frame
     void Update () {
         if( Input.GetButtonDown("Switch Weapons") && script.currentGun < script2.currentCount ) {
             Weapon_Change();
         }
         else if( Input.GetButtonDown("Switch Weapons") && script.currentGun >= script2.currentCount ) {
             First_Weapon();
         }
     }
     void Weapon_Change() {
                 
     Guns Result = script2.CurrentGuns.Find(
         delegate(Guns Gn) 
         {
             return Gn.gunCount == script.currentGun;
         }
         );
         if (Result != null)
         {
             script.gunType = Result.gunType;
             script.Range = Result.Range;
             script.Damage = Result.Damage;
             script.Accuracy = Result.Accuracy;
             script.shotsFired = Result.shotsFired;
             script.vertRecoil = Result.vertRecoil;
             script.sideRecoil = Result.sideRecoil;
             script.maxClip = Result.maxClip;
             script.maxAmmo = Result.maxAmmo;
             script.coolDown = Result.coolDown;
         }
         script.currentGun += 1;
         script.lastGun = script2.currentCount;
     }
     void First_Weapon() {
         Guns Result = script2.CurrentGuns.Find(
         delegate(Guns Gn) 
         {
             return Gn.gunCount == 0;
         }
         );
         if (Result != null)
         {
             script.gunType = Result.gunType;
             script.Range = Result.Range;
             script.Damage = Result.Damage;
             script.Accuracy = Result.Accuracy;
             script.shotsFired = Result.shotsFired;
             script.vertRecoil = Result.vertRecoil;
             script.sideRecoil = Result.sideRecoil;
             script.maxClip = Result.maxClip;
             script.maxAmmo = Result.maxAmmo;
             script.coolDown = Result.coolDown;
         }
         script.currentGun = 0;
         script.lastGun = script2.currentCount;
     }
 }
 
              no when i go through the list of weapons the first time it works but the second time it does not, there are no errors though.
Answer by mirrornineteen · Aug 29, 2013 at 01:25 AM
I've solved my problem the problem was that i was switching to the 0 gun when i should have been switching to number 1. all i did was change the script.currentGun at the bottom to be 1 and it fixed it.
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
problem with weapon animation -.- 0 Answers
Trading and cargo management data structures 0 Answers
Hunger system help - Money to be made 0 Answers