im making a wolfenstein 3d style fps, so the weapon sprites use canvas layers:
and i have a weapon swapping system, and i do not know how to make it hide the canvas layer of the weapon.
weaponswapping code:
extends Node3D
var Current_Weapon = 0
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)
func _process(delta):
if Current_Weapon == get_child_count():
Current_Weapon = 0
#ask godot forums how to make previous weapon thing
if Input.is_action_just_released("Next_Weapon"):
Current_Weapon = Current_Weapon+1
switch_weapon()
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)
weapon code:
extends Node3D
@onready var Weapon_Sprite = $CanvasLayer/Control/WeaponSprite
@onready var Hitscan = $Hitscan.get_children()
var can_fire = true
func _ready():
Weapon_Sprite.play("Idle")
func check_hit():
for ray in Hitscan:
if ray.is_colliding():
if ray.get_collider().is_in_group("Enemy"):
ray.get_collider().take_damage(5)
func _process(delta):
if Input.is_action_just_pressed("main_fire_weapon") and can_fire:
Weapon_Sprite.play("Fire")
check_hit()
can_fire = false
await Weapon_Sprite.animation_finished
can_fire = true
Weapon_Sprite.play("Idle")