[LayaAir 2.0]Cannot read property 'rayCast' of undefined
export default class indexscene extends Laya.Script {
constructor(){
super();
this.rotation = new Laya.Vector3(0, 0.01, 0);
this.point = new Laya.Vector2();
this.ray = new Laya.Ray(new Laya.Vector3(),new Laya.Vector3());
//1.开启第四个参数
let config3D = new Laya.Config3D();
config3D.isAlpha = true;
Laya3D.init(0, 0, config3D);
Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
//2.设置舞台背景色为空
Laya.stage.bgColor = null;
this.scene = new Laya.Scene3D();
this.camera = new Laya.Camera(0, 0.1, 100);
Laya.stage.addChild(this.scene);
this.scene.addChild(this.camera);
this.camera.transform.translate(new Laya.Vector3(0, 3.5, 1));
this.camera.transform.rotate(new Laya.Vector3(-15, 0, 0), true, false);
//3.清除照相机颜色
this.camera.clearColor = null;
this.directionLight = new Laya.DirectionLight();
this.scene.addChild(this.directionLight);
this.directionLight.direction = new Laya.Vector3(0, -0.8, -1);
this.directionLight.color = new Laya.Vector3(0.7, 0.6, 0.6);
Laya.Sprite3D.load("res/scene/LayaScene_webgl_sky/Conventional/webgl_sky.lh", Laya.Handler.create(this, this.onLoadFinish));
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
}
onLoadFinish(layaMonkey){
this.layaMonkey=this.scene.addChild(layaMonkey);
// Laya.timer.frameLoop(1, this, this.onFrameLoop);
}
onFrameLoop(){
this.layaMonkey.transform.rotate(this.rotation, false);
}
mouseDown(){
this.point.x = Laya.MouseManager.instance.mouseX;
this.point.y = Laya.MouseManager.instance.mouseY;
//产生射线
this.camera.viewportPointToRay(this.point, this.ray);
var out = new Laya.CannonHitResult();
this.scene.cannonPhysicsSimulation.rayCast(this.ray,out);
if(out.succeeded)
{
console.log(111);
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
程程
赞同来自:
Laya_z
赞同来自: