| 123456789101112131415161718192021222324252627 | import { _decorator, Component, ProgressBar } from 'cc';import { Role, RoleState } from '../Role';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;        if (hp <= 0) {            // this._role.playAnimation(RoleState.Die);            this._curHp = 0;            this._progressBar.progress = 0;        }    }}
 |