ok let's look at your code again:
is this working? are the weapons hidden when the game starts?
func _ready():
for child in get_child_count():
get_child(child).hide()
get_child(child).set_process(false)
get_child(Current_Weapon).show()
get_child(Current_Weapon).set_process(true)
instead of using for child in get_child_count()
I would use:
for i in get_children():
i.hide()
this could be causing problems:
get_child(Current_Weapon).set_process(true)
use a variable to tell the weapon if it should be active or not, setting this to true or false could be causing show()
and hide()
to not work.
var is_active : bool = true
func _process(delta):
if is_active:
if Input.is_action_just_pressed... etc
for i in get_children():
i.hide()
i.is_active = false
get_child(Current_Weapon).show()
get_child(Current_Weapon).is_active = true
Current_weapon
is an int? so you are using the index for get_child.
you should make sure the variable is restored to 0 if it overflows, otherwise it will return null
https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-child
if Input.is_action_just_released("Next_Weapon"):
Current_Weapon = Current_Weapon+1
if Current_Weapon > 3:#max number weapons
Current_Weapon = 0
switch_weapon()
here is the same thing, the problem is probably because you are setting process to false, which disables logic on the node and prevents the show()
and hide()
functions from working?
func switch_weapon():
for child in get_child_count():
get_child(child).hide()
get_child(child).set_process(false)
get_child(Current_Weapon-1).show()
get_child(Current_Weapon-1).set_process(true)
you are also using Current_Weapon-1
for some reason.
also this code is problematic, I would just remove it:
if Current_Weapon == get_child_count():
Current_Weapon = 0
also try adding a print to
if Input.is_action_just_released("Next_Weapon"):
Current_Weapon = Current_Weapon+1
switch_weapon()
print("next weapon")
if you are using the scroll wheel it could be causing problems, the scroll wheel is weird. try using a button like q
and see if it works.