LifeBar.ts 768 B

1234567891011121314151617181920212223242526
  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. 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. if (hp <= 0) {
  18. // this._role.playAnimation(RoleState.Die);
  19. this._curHp = 0;
  20. this.progressBar.progress = 0;
  21. }
  22. }
  23. }