class_name DamageSource extends Node

@export var damage: int
@export var raycast: Raycast

func _ready() -> void:
	raycast.enabled = false

func raycast_to_target() -> Option:
	raycast.force_raycast_update()
	return raycast.hit

func try_damage() -> void:
	match raycast_to_target():
		var option when option.is_some():
			var hit = option.unwrap()
			var collider = hit.collider
			match NodeExt.find_child_variant(collider, Health):
				var node when node.is_some():
					var health: Health = node.unwrap()
					health.apply_damage(damage)
				_: pass
		_: pass
