import { _decorator, Node, Vec3 } from 'cc'; import { Role } from '../Role'; import { RoleData } from '../../../DataItem/ItemData'; import { LifeBar } from './LifeBar'; import { GameMgr } from '../../GameFrameWork/GameMgr'; const { ccclass, property } = _decorator; @ccclass('MyRole') export class MyRole extends Role { private _lifeBar: LifeBar = null; private _enemies: Node = null; protected onLoad(): void { this._lifeBar = this.node.getComponent(LifeBar); this._enemies = this.node.parent.parent.parent.getChildByName("EnemyMgr"); //this._enemies = find("GameRoot/EnemyMgr"); } init(name: string, pos: Vec3, data: RoleData[]) { super.init(name, pos, data, 1) this._initLifeBar(); } //初始化血条 private _initLifeBar(){ this._lifeBar._curHp = this.hp; this._lifeBar._totalHp = this.hp; } update(deltaTime: number) { super.update(deltaTime) super.stop() if(!this.isAttacking){ super.getEnemiesAhead(this._enemies); } } stop(): void { if(this.node.getWorldPosition().x >= 1160){ this.isStop = true; } } }