LifeBar.ts 619 B

123456789101112131415161718192021
  1. import { _decorator, Component, ProgressBar } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('LifeBar')
  4. export class LifeBar extends Component {
  5. _curHp: number = null;
  6. _totalHp: number = null;
  7. private _progressBar: ProgressBar = null;
  8. protected onLoad(): void {
  9. this._progressBar = this.node.getChildByName("ProgressBar").getComponent(ProgressBar);
  10. }
  11. start() {
  12. this._progressBar.progress = this._curHp / this._totalHp;
  13. }
  14. updateProgressBar(hp: number) {
  15. this._curHp = hp;
  16. this._progressBar.progress = this._curHp / this._totalHp;
  17. }
  18. }