- Edited
So the problem i'm having is that whenever i press the fire button once it gets called multiple times. I have tried using _process and _physics_process and both give me the same issue.
Here is some backstory of what i'm trying to do:
Basicly i have a WeaponManager scene that handles shooting and ammo. Whenever the ammo reaches zero it instantly starts reloading because the function is getting called multiple times from one click. The interaction should be that ammo reaches zero and if you try to shoot with zero ammo it will go into reloading. But because the function being called multiple times from one press it will go into reloading instantly when it reaches zero,
`extends CharacterBody2D
@onready var weapon_manager: WeaponManager = $WeaponManager
var can_cycle_weapon = true
func _physics_process(delta):
if Input.is_action_just_pressed("equipWeapon"):
weapon_manager.equip_weapon()
if Input.is_action_pressed("Fire"):
weapon_manager.fire_weapon()
if Input.is_action_pressed("unequipWeapon"):
weapon_manager.unequip_weapon()
if Input.is_action_just_pressed("reload"):
weapon_manager.reload()
func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_WHEEL_UP and can_cycle_weapon:
weapon_manager.cycle_weapon(1)
can_cycle_weapon = false
await get_tree().create_timer(0.3).timeout
can_cycle_weapon = true
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN and can_cycle_weapon:
weapon_manager.cycle_weapon(-1)
can_cycle_weapon = false
await get_tree().create_timer(0.3).timeout
can_cycle_weapon = true`