basic healthbars for enemies

This commit is contained in:
2026-01-23 13:31:11 +01:00
parent 8b2bf3e32e
commit 4d419b9010
13 changed files with 139 additions and 18 deletions

View File

@@ -0,0 +1,26 @@
using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass]
public partial class CHealthbar : Node3D
{
private Sprite3D _currentHealth;
private float _initialXScale;
public override void _Ready()
{
Visible = false;
_currentHealth = GetNode<Sprite3D>("Health");
_initialXScale = _currentHealth.Scale.X;
}
public void OnHealthChanged(HealthChangedRecord healthChanged)
{
if (healthChanged.MaxHealth == 0) return;
Visible = true;
var healthPercentage = healthChanged.CurrentHealth / healthChanged.MaxHealth;
_currentHealth.Scale = new Vector3(_initialXScale * healthPercentage, _currentHealth.Scale.Y, _currentHealth.Scale.Z);
}
}