From 7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 23 Nov 2026 12:00:20 +0100 Subject: pes --- scripts/WeaponHolder.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'scripts/WeaponHolder.cs') diff --git a/scripts/WeaponHolder.cs b/scripts/WeaponHolder.cs index 210be60..6f6c7b2 100644 --- a/scripts/WeaponHolder.cs +++ b/scripts/WeaponHolder.cs @@ -2,9 +2,9 @@ using Godot; public partial class WeaponHolder : Node2D { - [Export] public PackedScene[] WeaponScenes { get; set; } + [Export] public PackedScene[] WeaponScenes { get; set; } = System.Array.Empty(); - private Weapon _currentWeapon; + private Weapon? _currentWeapon; public override void _Ready() { @@ -17,15 +17,22 @@ public partial class WeaponHolder : Node2D if (WeaponScenes == null || WeaponScenes.Length <= index || WeaponScenes[index] == null) return; + EquipWeaponScene(WeaponScenes[index]); + GD.Print($"WeaponHolder equipped weapon index: {index}"); + } + + public void EquipWeaponScene(PackedScene weaponScene) + { + if (weaponScene == null) + return; + if (_currentWeapon != null) { _currentWeapon.QueueFree(); } - _currentWeapon = WeaponScenes[index].Instantiate(); + _currentWeapon = weaponScene.Instantiate(); AddChild(_currentWeapon); - - GD.Print($"WeaponHolder equipped weapon index: {index}"); } public override void _UnhandledInput(InputEvent @event) @@ -40,4 +47,4 @@ public partial class WeaponHolder : Node2D if (@event.IsActionPressed("weapon_1")) EquipWeapon(0); else if (@event.IsActionPressed("weapon_2")) EquipWeapon(1); } -} \ No newline at end of file +} -- cgit v1.2.3