[LayaAirIDE 2.0]子弹添加了colliderShape后onUpdate移动,destroy会报错“Cannot read property 'getWorldTransform' of null”
发射时生成子弹:
onFire() {
if (this.isFire) {
Laya.Mesh.load("fly2/fly3-bullet.lm", Laya.Handler.create(this, function (m) {
let bullet = new Laya.MeshSprite3D(m);
this.Sn.addChild(bullet);
bullet.addComponent(BulletScript);
var bulletCollider = bullet.addComponent(Laya.PhysicsCollider);
var bulletShape = new Laya.MeshColliderShape();
bulletShape.mesh = bullet.meshFilter.sharedMesh;
bulletCollider.colliderShape = bulletShape;
}))
}
}
子弹组件BulletScript中
onStart() {
Laya.timer.once(1500, this, function () {
console.log("destroy");
this.owner.destroy();
});
}
onUpdate() {
this.owner.transform.translate(new Laya.Vector3(0, 0, -0.1));
}
onFire() {
if (this.isFire) {
Laya.Mesh.load("fly2/fly3-bullet.lm", Laya.Handler.create(this, function (m) {
let bullet = new Laya.MeshSprite3D(m);
this.Sn.addChild(bullet);
bullet.addComponent(BulletScript);
var bulletCollider = bullet.addComponent(Laya.PhysicsCollider);
var bulletShape = new Laya.MeshColliderShape();
bulletShape.mesh = bullet.meshFilter.sharedMesh;
bulletCollider.colliderShape = bulletShape;
}))
}
}
子弹组件BulletScript中
onStart() {
Laya.timer.once(1500, this, function () {
console.log("destroy");
this.owner.destroy();
});
}
onUpdate() {
this.owner.transform.translate(new Laya.Vector3(0, 0, -0.1));
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Sོ
赞同来自:
186*****880
赞同来自: