using Godot; public partial class WeaponHolder : Node2D { [Export] public PackedScene[] WeaponScenes { get; set; } private Weapon _currentWeapon; public override void _Ready() { // Equip the first weapon automatically EquipWeapon(0); } public void EquipWeapon(int index) { if (WeaponScenes == null || WeaponScenes.Length <= index || WeaponScenes[index] == null) return; if (_currentWeapon != null) { _currentWeapon.QueueFree(); } _currentWeapon = WeaponScenes[index].Instantiate(); AddChild(_currentWeapon); GD.Print($"WeaponHolder equipped weapon index: {index}"); } public override void _UnhandledInput(InputEvent @event) { // Handle shooting if (@event.IsActionPressed("shoot") && _currentWeapon != null) { _currentWeapon.Fire(GetGlobalMousePosition()); } // Handle swapping if (@event.IsActionPressed("weapon_1")) EquipWeapon(0); else if (@event.IsActionPressed("weapon_2")) EquipWeapon(1); } }