用户:
屑波特屑查看:0 回复:7 评论:0 创建时间:2023-01-05T16:28:24
接下来是代码:
//开关门
world.querySelectorAll('.门').forEach((e) => {//带有标签“门”的模型
e.open = 0//初始门的开关情况(0为关,1为开)
e.onClick(async ({ entity, button, clicker }) => {//如果点击门
if (button === 'action1') {//点击用的是右键(B)
if (e.open == 0) {//如果门关的
e.open = 1//设为开
e.meshOrientation = meshOrientation = new Box3Quaternion(0, 0.5, 0, 0.5)//让门旋转90度
e.position.x -= 2//将X-2(移到门框边缘)
e.position.z += 0.5//将Z+0.5(刚刚好卡在门框上)
} else if (e.open == 1) {//如果门开的
e.open = 0//设为关
e.meshOrientation = meshOrientation = new Box3Quaternion(0, 0, 0, 0)//恢复正常角度
e.position.x += 2//把门X坐标拉回来
e.position.z -= 0.5//把门Z坐标拉回来
}
}
})
})
//滑动门
world.querySelectorAll('.门2').forEach((e) => {//带有标签“门2”的模型
e.onClick(async ({ entity, button, clicker }) => {//如果点击门
if (button === 'action1') {//点击用的是右键(B)
e.position.y -= 80//将Y下降80(模拟离开)
await sleep (1000*2)//等待1*2=2秒
e.position.y += 80//回到真确位置
}
})
})