//refresh all the weapon on top void RefreshWeaponUI() { //clear everything foreach (Tds_WeaponMenu vCurMenu in vGameManager.vWeaponMenuList) { UpdateWeaponMenu(vCurMenu, null); } int vcpt = 0; foreach (Tds_Weapons vCurWeapon in ListWeapons) { //get the right menu Tds_WeaponMenu vCurMenu = vGameManager.vWeaponMenuList [vcpt]; //check if we are on the selected weapon if (vcpt == vCurWeapIndex) { vCurMenu.WepPanel.color = Color.yellow; } else { vCurMenu.WepPanel.color = Color.white; } //update the menu UpdateWeaponMenu(vCurMenu, vCurWeapon); //increase counter vcpt++; } }
//update current weapon menu void UpdateWeaponMenu(Tds_WeaponMenu vCurMenu, Tds_Weapons vCurWeapon) { if (vCurWeapon != null) { //enable current menu vCurMenu.WepPanel.gameObject.SetActive(true); //weapon sprite vCurMenu.WeaponSprite.sprite = vCurWeapon.vWeaponIcon; //ammo text vCurMenu.AmmoValue.text = vCurWeapon.vAmmoCur.ToString() + " / " + vCurWeapon.vAmmoSize; //ammo text vCurMenu.AmmoValue.text = vCurWeapon.vAmmoCur.ToString() + " / " + vCurWeapon.vAmmoSize; //ammo bar % shown vCurMenu.AmmoBar.fillAmount = (float)vCurWeapon.vAmmoCur / (float)vCurWeapon.vAmmoSize; //check if it's reloading current weapon if (IsReloading && vCurWeapon == ListWeapons[vCurWeapIndex]) { vCurMenu.ReloadImg.fillAmount = ((float)TimeToReload / 1f); } else if (!IsReloading && vCurWeapon.vAmmoCur == 0) { vCurMenu.ReloadImg.fillAmount = 1f; } else { vCurMenu.ReloadImg.fillAmount = 0f; } } else { //disable the whole menu if there is no weapon there vCurMenu.WepPanel.gameObject.SetActive(false); } }