現在、ReadOnly 属性を持つ VariableSettings ノードの taken_damage/value を削除・変更した状態です。ダメージ表示数字を作成する方法で困っています。
チュートリアル通りに簡易的な Label を作成し、自身の VariableSettings ノードの taken_damage/value は読み取れますが、
現在 2 つの課題があります:
- 別のオブジェクトの VariableSettings ノードの taken_damage/value を跨オブジェクトで読み取る方法が分かりません。
- トリガー条件の設定方法がわかりません。
ご教示いただければ幸いです。
///
Currently, I have modified or deleted the taken_damage/value in the read-only VariableSettings node, and I’m stuck on creating damage display numbers.
I’ve followed a tutorial to create a simple Label that can read the taken_damage/value from my own VariableSettings node, but now I’m facing two issues:
- I can’t figure out how to read the taken_damage/value from another object’s VariableSettings node across objects.
- I’m unsure about how to set up the trigger conditions for this.
Any guidance would be greatly appreciated!
///
请问现在改变删除了只读的VariableSettings节点的taken_damage/value,
我该怎么制作伤害显示数字,
1.我按照教程制作了简单的Label,可以读取自己的VariableSettings节点的taken_damage/value,
2.但是目前卡在了跨对象读取另一个对象的VariableSettings节点的taken_damage/value,而且触发条件不知道怎么搞,请赐教
///
以下が現在のコードです:
Here is the current code:
extends Node2D
@onready var label: Label = $Label
@onready var variable_settings = $“VariableSettings” # 假设VariableSettings是父节点中的同级节点
var position_tween: Tween
var scale_tween: Tween
var fade_tween: Tween
func _ready() → void:
scale = Vector2.ZERO
# 从VariableSettings节点获取taken_damage/value值
var damage_amount = variable_settings.get(“taken_damage/value”)
display_damage_text(damage_amount)
func display_damage_text(damage_amount: float) → void:
# 清除可能存在的旧动画
if position_tween != null and position_tween.is_valid():
position_tween.kill()
if scale_tween != null and scale_tween.is_valid():
scale_tween.kill()
# 设置伤害文本
label.text = str(damage_amount)
label.modulate = Color.WHITE # 重置透明度
# 生成随机偏移量(X方向-10到10像素,Y方向不变)
var random_offset = Vector2(randf_range(-10, 10), 0)
# 创建所有动画
position_tween = create_tween().set_parallel(false) # 串行动画
scale_tween = create_tween().set_parallel(false)
fade_tween = create_tween()
# 第一阶段:弹出效果(缩放+上移+随机偏移)
scale_tween.tween_property(self, "scale", Vector2.ONE, 0.2)
position_tween.tween_property(
self, "global_position",
global_position + Vector2.UP * 16 + random_offset,
0.3
)
# 第二阶段:继续上移+渐隐
position_tween.tween_property(
self, "global_position",
global_position + Vector2.UP * 40 + random_offset,
0.3
)
fade_tween.tween_property(label, "modulate:a", 0.0, 0.4) # 透明度降到0
# 第三阶段:缩小(与渐隐同步)
scale_tween.tween_property(self, "scale", Vector2.ZERO, 0.4)