123456789101112131415161718192021 |
- import { _decorator, Component, ProgressBar } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('LifeBar')
- export class LifeBar extends Component {
- _curHp: number = null;
- _totalHp: number = null;
- private _progressBar: ProgressBar = null;
- protected onLoad(): void {
- this._progressBar = this.node.getChildByName("ProgressBar").getComponent(ProgressBar);
- }
- start() {
- this._progressBar.progress = this._curHp / this._totalHp;
- }
- updateProgressBar(hp: number) {
- this._curHp = hp;
- this._progressBar.progress = this._curHp / this._totalHp;
- }
- }
|