[LayaAirIDE 2.0]laya3d物体碰撞与触发检测的问题

import BoxMove from "./BoxMove";
export default class GameUI extends Laya.Scene {
constructor() {
super();
//加载场景文件
this.loadScene("test/TestScene.scene");
//添加3D场景
var scene = Laya.stage.addChild(new Laya.Scene3D());
//添加照相机
var camera = (scene.addChild(new Laya.Camera(0, 0.1, 100)));
camera.transform.translate(new Laya.Vector3(0, 3, 3));
camera.transform.rotate(new Laya.Vector3(-30, 0, 0), true, false);
camera.clearColor = null;
//添加方向光
var directionLight = scene.addChild(new Laya.DirectionLight());
directionLight.color = new Laya.Vector3(0.6, 0.6, 0.6);
directionLight.transform.worldMatrix.setForward(new Laya.Vector3(1, -1, 0));
//添加自定义模型1
var box = scene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1)));
box.addComponent(Laya.PhysicsCollider);
var Rig=box.addComponent(Laya.Rigidbody3D);
Rig.colliderShape=new Laya.BoxColliderShape(1,1,1);
Rig.isTrigger=true;
box.transform.translate(new Laya.Vector3(0, 2, 0), false);
box.addComponent(BoxMove);
//添加自定义模型2
var box1 = scene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1)));
var phy = box1.addComponent(Laya.PhysicsCollider);
phy.colliderShape=new Laya.BoxColliderShape(1,1,1);
}
}
 
 
 
export default class BoxMove extends Laya.Script { 
constructor() {
super();
}
onTriggerEnter()
{
console.log("111");
}
onTriggerStay()
{
console.log("111");
}
onTriggerExit()
{
console.log("111");
}
onEnable() {

onDisable() {
}
}
//这是两个类,直接可以就不会发生触发效果,什么都不输出,还是我哪里写错了,求指点。谢谢
 
 
已邀请:

bpmf_d

赞同来自:

3D物体要继承 Laya.Script3D 而不是 Laya.Script

要回复问题请先

商务合作
商务合作