Example damage label
This commit is contained in:
40
battle/ui/DamageLabel.gd
Normal file
40
battle/ui/DamageLabel.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
class_name DamageLabel extends Label3D
|
||||
|
||||
@export var timer:Timer
|
||||
@export var speed:Vector3 = Vector3(0, 1, 0)
|
||||
|
||||
func onTimeout() -> void:
|
||||
self.visible = false
|
||||
queue_free()
|
||||
print("Damage label removed")
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
self.position += speed * delta
|
||||
|
||||
func showDamage(
|
||||
parent:Node3D,
|
||||
amount:int,
|
||||
isCritical:bool
|
||||
) -> void:
|
||||
if amount == 0:
|
||||
return
|
||||
|
||||
text = str(amount)
|
||||
|
||||
if amount > 0:
|
||||
# Healing
|
||||
modulate = Color.GREEN
|
||||
outline_modulate = Color.TRANSPARENT
|
||||
elif isCritical:
|
||||
# Crit
|
||||
modulate = Color.RED
|
||||
outline_modulate = Color.BLACK
|
||||
else:
|
||||
# DMG
|
||||
modulate = Color.RED
|
||||
outline_modulate = Color.TRANSPARENT
|
||||
|
||||
parent.add_child(self)
|
||||
self.position = Vector3.ZERO
|
||||
|
||||
timer.timeout.connect(onTimeout)
|
||||
1
battle/ui/DamageLabel.gd.uid
Normal file
1
battle/ui/DamageLabel.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b86wqbqmsrv5b
|
||||
16
battle/ui/DamageLabel.tscn
Normal file
16
battle/ui/DamageLabel.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://baxswkivvo5rs"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b86wqbqmsrv5b" path="res://battle/ui/DamageLabel.gd" id="1_6dg8x"]
|
||||
|
||||
[node name="DamageLabel" type="Label3D" node_paths=PackedStringArray("timer")]
|
||||
billboard = 1
|
||||
render_priority = 1
|
||||
outline_modulate = Color(1, 0, 0, 1)
|
||||
text = "-%%%%%"
|
||||
script = ExtResource("1_6dg8x")
|
||||
timer = NodePath("Timer")
|
||||
metadata/_custom_type_script = "uid://b86wqbqmsrv5b"
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
autostart = true
|
||||
Reference in New Issue
Block a user