3.7 3.8版本都试过,都报错。
player 有一个脚本,给sensor碰撞体注册回调函数,然后这个回调函数中的this.xxx全部都报错,
Cannot read property ‘xxx’ of undefined
this.sensorCollider.on(Contact2DType.BEGIN_CONTACT,this._onSensorBeginContact);
public _onSensorBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact): void{
if(otherCollider.tag==GameConfigTable.monster_collider_tag){
//console.info(BattleSceneManager.instance.playerBattleUnit.node.name);
console.info(**this.node**.name);
//this.sensoredMonstersArray.push(otherCollider.node);
}
//还有注册一个事件,当怪物死亡,将怪物从这里移除。
EventManager.Regist(EventTypeForEventManager.MonsterDie,(param:{tag:string,monsterUnit:MonsterBattleUnit})=>{
utilsKxp.deleteElementOfArray(param.monsterUnit.node,this.sensoredMonstersArray);
},this)
}
会报错
[PreviewInEditor] Cannot read property ‘node’ of undefined.
