| 1234567891011121314151617181920212223242526272829 | 
							- 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;
 
-     private _role: Role = null;
 
-     protected onLoad(): void {
 
-         this._role = this.node.getComponent(Role);
 
-         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;
 
-         }
 
-     }
 
- }
 
 
  |