// Update is called once per frame void Update() { GameObject inventory = GameObject.FindGameObjectWithTag("Inventory"); if (inventory != null) { InventoryScript script = inventory.GetComponent <InventoryScript>(); int slotCounter = 0; foreach (GunParameters gp in script.GetWeaponsInInventory()) { slotCounter += 1; if (slotCounter == 1) { if (gp != null) { slot1.gunParams = gp; } } else if (slotCounter == 2) { if (gp != null) { slot2.gunParams = gp; } } } } }
GunParameters GenerateNewGunParameters() { GameObject inventoryObject = GameObject.FindGameObjectWithTag("Inventory"); GunParameters gunParameters1; GunParameters gunParameters2; GunParameters newParameters = null; if (inventoryObject != null) { InventoryScript inventory = inventoryObject.GetComponent <InventoryScript>(); List <GunParameters> listOfGunParameters = inventory.GetWeaponsInInventory(); int numOfEquippedGuns = 0; foreach (GunParameters gp in listOfGunParameters) { if (gp != null) { numOfEquippedGuns += 1; } } if (numOfEquippedGuns >= 2) { gunParameters1 = listOfGunParameters[0]; gunParameters2 = listOfGunParameters[1]; GunType newGunType = GenerateNewGunType(); int newDamage = GenerateNewGunDamage(gunParameters1.damage, gunParameters2.damage); int newMaxAmmo = GenerateNewGunMaxAmmo(gunParameters1.maxAmmo, gunParameters2.maxAmmo); float newRateOfFire = GenerateNewGunRateOfFire(gunParameters1.rateOfFire, gunParameters2.rateOfFire); float newReloadSpeed = GenerateNewGunReloadSpeed(gunParameters1.reloadSpeed, gunParameters2.reloadSpeed); float newHitscanRange = GenerateNewGunHitscanRange(gunParameters1.hitscanRange, gunParameters2.hitscanRange); GameObject newGameObject = GenerateNewGameObject(gunParameters1.currentGunObject, gunParameters2.currentGunObject); ProjectileParameters newProjectileParams = GenerateNewProjectileParameters(gunParameters1.projectileParameters, gunParameters2.projectileParameters); newParameters = new GunParameters(newGunType, newDamage, newMaxAmmo, newRateOfFire, newReloadSpeed, newHitscanRange, newGameObject, newProjectileParams); } else if (numOfEquippedGuns == 1) { foreach (GunParameters gp in listOfGunParameters) { if (gp != null) { newParameters = gp; } } } } return(newParameters); }