Slash-The-Hordes/assets/Scripts/Game/UI/GameUI.ts

24 lines
742 B
TypeScript
Raw Normal View History

2022-11-16 13:04:23 +00:00
import { Component, ProgressBar, _decorator } from "cc";
2022-11-28 10:49:16 +00:00
import { Player } from "../Unit/Player/Player";
2022-11-28 11:19:04 +00:00
import { UnitLevel } from "../Unit/UnitLevel";
2022-11-16 13:04:23 +00:00
const { ccclass, property } = _decorator;
@ccclass("GameUI")
export class GameUI extends Component {
@property(ProgressBar) private xpBar: ProgressBar;
private playerLevel: UnitLevel;
public init(player: Player): void {
this.playerLevel = player.Level;
this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this);
this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this);
this.xpBar.progress = 0;
}
private updateProgressBar(): void {
this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP;
}
}