weapon system done
This commit is contained in:
1 parent
1af59b921f
commit
f07d687be8
20 files changed
+1504
-52
No files matched your search
@@ -14,6 +14,12 @@ public class WeaponHUD : MonoBehaviour
|
||||
[Tooltip("彈藥 Text (TMP),例如「12 / 12」")]
|
||||
public TextMeshProUGUI ammoText;
|
||||
|
||||
[Tooltip("換彈提示 (換彈中才顯示)")]
|
||||
public GameObject reloadTips;
|
||||
|
||||
[Tooltip("換彈剩餘時間 Text (TMP),例如「1.4s」,換彈中才顯示")]
|
||||
public TextMeshProUGUI reloadTimeText;
|
||||
|
||||
[Header("命中提示")]
|
||||
public Color bodyColor = Color.white;
|
||||
public Color headColor = new Color(1f, 0.25f, 0.25f);
|
||||
@@ -25,10 +31,13 @@ public class WeaponHUD : MonoBehaviour
|
||||
private float hitMarkerTimer;
|
||||
private int shownAmmo = -1;
|
||||
private bool shownReloading;
|
||||
private int shownReloadTenths = -1; // 以 0.1 秒為單位,數字有變才更新文字
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (hitMarker != null) hitMarker.enabled = false;
|
||||
if (reloadTips != null) reloadTips.SetActive(false);
|
||||
if (reloadTimeText != null) reloadTimeText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
@@ -44,6 +53,7 @@ public class WeaponHUD : MonoBehaviour
|
||||
|
||||
UpdateHitMarker();
|
||||
UpdateAmmoText(current);
|
||||
UpdateReloadTime(current);
|
||||
}
|
||||
|
||||
void Subscribe(HitscanWeapon weapon)
|
||||
@@ -80,5 +90,19 @@ public class WeaponHUD : MonoBehaviour
|
||||
shownAmmo = weapon.Ammo;
|
||||
shownReloading = weapon.IsReloading;
|
||||
ammoText.text = shownReloading ? "換彈中..." : $"{shownAmmo} / {weapon.data.magazineSize}";
|
||||
if (reloadTips != null) reloadTips.SetActive(shownReloading);
|
||||
if (reloadTimeText != null) reloadTimeText.gameObject.SetActive(shownReloading);
|
||||
}
|
||||
|
||||
// 換彈剩餘時間,精確到 0.1 秒 (無條件進位,避免還沒換完就顯示 0.0s)
|
||||
void UpdateReloadTime(HitscanWeapon weapon)
|
||||
{
|
||||
if (reloadTimeText == null || weapon == null || !weapon.IsReloading) return;
|
||||
|
||||
int tenths = Mathf.CeilToInt(weapon.ReloadRemaining * 10f);
|
||||
if (tenths == shownReloadTenths) return;
|
||||
|
||||
shownReloadTenths = tenths;
|
||||
reloadTimeText.text = $"{tenths / 10f:F1}s";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user