
小球开始碰撞后 由于弹性反弹然后再次进行碰撞多次,但是最终定格到开始碰撞?正常逻辑应该是onTriggerExit,结束碰撞时执行,仅执行一次。怎么使用代码判断呢,我的代码是
`const { regClass, property } = Laya;
@regClass()
export class QiuScript extends Laya.Script {
//declare owner : Laya.Sprite3D;
//declare owner : Laya.Sprite;
@property(String)
public text: string = "";
// 当触发碰撞开始时(适用于触发器)
onTriggerEnter(other: any, self: any, contact: any): void {
// other 就是与物体A发生碰撞的那个对象!
if (other.label == "prize_gezi") {
// 此处省略逃脱奖励的逻辑
console.log("开始碰撞:小球碰到了:", other.owner.name); // 打印对方的名字
}
// 你可以通过 other.owner 获取到对方节点,进行后续操作
let hitObject = other.owner;
// ... 处理碰撞逻辑 ...
}
onTriggerExit(other: any | Laya.ColliderBase, self?: Laya.ColliderBase, contact?: any): void {
if (other.label == "prize_gezi") {
// 此处省略逃脱奖励的逻辑
console.log("碰到格子"+other.owner.name+"停下来了"); // 打印对方的名字
}
}
}`