update
This commit is contained in:
@@ -6,17 +6,29 @@ extends Sprite3D
|
||||
@onready var border: ColorRect = $SubViewport/Border
|
||||
@onready var health: Node = get_parent().get_node("Health")
|
||||
@onready var shield: Node = get_parent().get_node("Shield")
|
||||
@onready var enemy: CharacterBody3D = get_parent()
|
||||
|
||||
var style_normal: StyleBoxFlat
|
||||
var style_aggro: StyleBoxFlat
|
||||
|
||||
func _ready() -> void:
|
||||
texture = viewport.get_texture()
|
||||
health_bar.max_value = health.max_health
|
||||
shield_bar.max_value = shield.max_shield
|
||||
border.visible = false
|
||||
style_normal = health_bar.get_theme_stylebox("fill").duplicate()
|
||||
style_aggro = style_normal.duplicate()
|
||||
style_aggro.bg_color = Color(0.2, 0.4, 0.9, 1)
|
||||
EventBus.target_changed.connect(_on_target_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
health_bar.value = health.current_health
|
||||
shield_bar.value = shield.current_shield
|
||||
var player: Node = get_tree().get_first_node_in_group("player")
|
||||
if player and enemy.target == player:
|
||||
health_bar.add_theme_stylebox_override("fill", style_aggro)
|
||||
else:
|
||||
health_bar.add_theme_stylebox_override("fill", style_normal)
|
||||
|
||||
func _on_target_changed(_player: Node, target: Node) -> void:
|
||||
border.visible = (target == get_parent())
|
||||
|
||||
Reference in New Issue
Block a user