using UnityEngine; using UnityEngine.InputSystem; // 依照 StartUI 選的武器,只啟用對應的那一把槍 // 測試模式下可以用 1~4 鍵切換,方便比較手感 public class WeaponLoadout : MonoBehaviour { [Header("武器 (順序對應 1~4 鍵)")] [Tooltip("每把槍模型上的 HitscanWeapon")] public HitscanWeapon[] weapons; public HitscanWeapon Current { get; private set; } private bool allowSwitch; void Start() { GameSettings settings = GameSettings.Load(); allowSwitch = settings.isTest; int index = 0; for (int i = 0; i < weapons.Length; i++) { if (weapons[i] != null && weapons[i].data != null && weapons[i].data.weaponName == settings.weapon) { index = i; break; } } Equip(index); } void Update() { if (!allowSwitch || Keyboard.current == null) return; if (Keyboard.current.digit1Key.wasPressedThisFrame) Equip(0); else if (Keyboard.current.digit2Key.wasPressedThisFrame) Equip(1); else if (Keyboard.current.digit3Key.wasPressedThisFrame) Equip(2); else if (Keyboard.current.digit4Key.wasPressedThisFrame) Equip(3); } void Equip(int index) { if (index < 0 || index >= weapons.Length || weapons[index] == null) return; for (int i = 0; i < weapons.Length; i++) { if (weapons[i] != null) weapons[i].gameObject.SetActive(i == index); } Current = weapons[index]; } }