basic healthbars for enemies
This commit is contained in:
26
components/health/CHealthbar.cs
Normal file
26
components/health/CHealthbar.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user