string AmmoInfo(RangedWeapon rw, int firingModeIndex) { AmmunitionStats a = rw.GetAmmunitionStats(firingModeIndex); MagazineStats m = rw.GetMagazineStats(firingModeIndex); string s = ""; if (a == null) { if (m == null) { s = "INFINITE"; } else { s = m.magazine.current + "/INF"; } } else { if (m == null) { s = ph.a.GetStock(a.ammoType).ToString(); } else { s = m.magazine.current + "/" + (ph.a.GetStock(a.ammoType) - m.magazine.current); } } return(s); }
// Update is called once per frame void Update() { /* * if (prs.healthCurrent != healthPrev) * { * //HealthMeterUpdate(); * } * healthPrev = prs.healthCurrent; */ #region Health HUD healthCounter.text = ph.ph.health.current.ToString(); FillMeter(healthBar, ph.ph.health.current, ph.ph.health.max); if (ph.ph.health.IsCritical()) { healthCounter.color = resourceCriticalColour; // Do other stuff for critical health e.g. greyscale screen, warnings } else { healthCounter.color = resourceNormalColour; } #endregion #region Basic reticle and interacting RaycastHit lookingAt; if (Physics.Raycast(ph.pc.head.transform.position, transform.forward, out lookingAt, lookRange, lookDetection)) { Character c = null; DamageHitbox d = lookingAt.collider.GetComponent <DamageHitbox>(); if (d != null) { c = Character.FromHitbox(d); if (c != null) { switch (ph.faction.Affiliation(c.faction)) { case FactionState.Allied: ColourReticle(allyColour); break; case FactionState.Hostile: ColourReticle(enemyColour); break; default: ColourReticle(reticleDefaultColour); break; } } else { ColourReticle(reticleDefaultColour); } } else { ColourReticle(reticleDefaultColour); } // Do interacting stuff } else { ColourReticle(reticleDefaultColour); } #endregion #region Weapon HUD RangedWeapon rw = ph.wh.CurrentWeapon(); bool activeWeapon = !ph.wh.IsSwitchingWeapon; reticleUp.gameObject.SetActive(activeWeapon); reticleDown.gameObject.SetActive(activeWeapon); reticleLeft.gameObject.SetActive(activeWeapon); reticleRight.gameObject.SetActive(activeWeapon); ammoDisplay.gameObject.SetActive(activeWeapon); opticsOverlay.gameObject.SetActive(activeWeapon); opticsTransition.gameObject.SetActive(activeWeapon); if (activeWeapon == true) { if (rw.optics == null) { ADSTransition(0, null); } float accuracy = ph.wh.accuracyModifier.NewFloat(ph.wh.standingAccuracy); float rp = (accuracy + rw.accuracy.projectileSpread) * Screen.height / ph.pc.fieldOfView; reticleUp.rectTransform.anchoredPosition = Vector3.up * rp; reticleDown.rectTransform.anchoredPosition = Vector3.down * rp; reticleLeft.rectTransform.anchoredPosition = Vector3.left * rp; reticleRight.rectTransform.anchoredPosition = Vector3.right * rp; firingMode.text = rw.firingModes[rw.firingModeIndex].name; ammoCounter.text = AmmoInfo(rw, rw.firingModeIndex); AmmunitionStats a = rw.GetAmmunitionStats(rw.firingModeIndex); MagazineStats m = rw.GetMagazineStats(rw.firingModeIndex); if (a == null) { if (m == null) { FillMeter(ammoBar, 1, 1); } else { FillMeter(ammoBar, m.magazine.current, m.magazine.max); } } else { if (m == null) { FillMeter(ammoBar, ph.a.GetStock(a.ammoType), ph.a.GetMax(a.ammoType)); } else { FillMeter(ammoBar, m.magazine.current, m.magazine.max); } } } #endregion }