Slash-The-Hordes/assets/Scripts/Game/Player/PlayerUI/PlayerHealthUI.ts

20 lines
640 B
TypeScript
Raw Normal View History

2022-11-08 18:45:57 +00:00
import { Component, ProgressBar, _decorator } from "cc";
import { UnitHealth } from "../UnitHealth";
const { ccclass, property } = _decorator;
@ccclass("PlayerHealthUI")
export class PlayerHealthUI extends Component {
@property(ProgressBar) public healthBar: ProgressBar;
private health: UnitHealth;
public init(health: UnitHealth): void {
this.healthBar.progress = 1;
this.health = health;
this.health.HealthPointsChangeEvent.on(this.updateHealthBar, this);
}
private updateHealthBar(): void {
this.healthBar.progress = this.health.HealthPoints / this.health.MaxHealthPoints;
}
}