diff options
| author | alex <[email protected]> | 2026-07-25 17:14:11 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-25 17:14:11 +0200 |
| commit | a6e7c49a162ada8ec0883fccb1da7313b03ba2ec (patch) | |
| tree | 2e374c703ea3591e9f7053477bb1135fe608f58f /scripts | |
| parent | 023c4f003d58c27cd2677307abe2c65bb09c2681 (diff) | |
| download | godot-testing-main.tar.xz godot-testing-main.zip | |
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/WeaponHolder.cs | 43 | ||||
| -rw-r--r-- | scripts/WeaponHolder.cs.uid | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/scripts/WeaponHolder.cs b/scripts/WeaponHolder.cs new file mode 100644 index 0000000..210be60 --- /dev/null +++ b/scripts/WeaponHolder.cs @@ -0,0 +1,43 @@ +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<Weapon>(); + 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); + } +}
\ No newline at end of file diff --git a/scripts/WeaponHolder.cs.uid b/scripts/WeaponHolder.cs.uid new file mode 100644 index 0000000..089d4a7 --- /dev/null +++ b/scripts/WeaponHolder.cs.uid @@ -0,0 +1 @@ +uid://bfqeoell73w34 |
