Aar0n 您写的我试了,如果是新建,且没有值的情况下确实不会报错,但如果是已存在,比如先设置sp.getComponent(ChainCollider).points = "25,25,50,50";运行后,再改变值时,就会报错。
如下使用2d示例项目中代码,改写的,点击2次场景就会报错。:
onStageClick(e: Laya.Event): void {
//停止事件冒泡,提高性能,当然也可以不要
e.stopPropagation();
//舞台被点击后,使用对象池创建子弹
let flyer: Laya.Sprite = Laya.Pool.getItemByCreateFun("bullet", this.bullet.create, this.bullet);
flyer.pos(Laya.stage.mouseX, Laya.stage.mouseY);
this._gameBox.addChild(flyer);
this._chains.points="118,99,158,70,218,99,258,70,318,99,358,70,418,99,458,70,518,99,558,70";
}
/**开始游戏,通过激活本脚本方式开始游戏*/
startGame(): void {
if (!this._started) {
this._started = true;
this.enabled = true;
}
var ground=this.owner.getChildByName("ground");
ground.addComponent(Laya.ChainCollider);
this._chains=ground.getComponent(Laya.ChainCollider);
}