- Edited
JetteBoyTV use classes.
1 - create a new script that will be the base of your class:
weapon_class.gd
class_name WeaponClass
extends Node3D
func weapon_sprite_visibility(vis : bool = false) -> void:
pass
2 - now, in each of the scripts of each of the weapons (or the same if they share the same script), extend from WeaponClass
instead of Node3D
and override the function weapon_sprite_visibility
extends WeaponClass
func weapon_sprite_visibility(vis : bool = false) -> void:
$CanvasLayer.visible = vis
3 - finally, on weapon swap, call the function to hide the CanvasLayer
:
weapon_sprite_visibility(true)
oh, I see what you mean, I wrote all this and you are asking something else.
well, start by putting your weapons into a dictionary on ready, each will have a number:
var weapon_nodes : Dictionary = {}
func _ready():
weapon_nodes[0] = $Knife
weapon_nodes[1] = $HandGun
now, when going to next, add 1, check if it overflows and if it does go to 0
Current_weapon += 1
if Current_weapon > 2:#3 weapons
Current_weapon = 0
#then hide the weapons
for i in get_children():
i.hide()
#then show the current one
weapon_nodes.get(Current_weapon, $Knife).show()