用户:Cen查看:12 回复:11 评论:12 创建时间:2022-05-29T15:51:04
/*
在大型地图中,去一个地方很麻烦需要跑图
然而一个传送菜单就能很好的解决这个问题
(第一次发教程,有误请在评论区指出,Thanks♪(・ω・)ノ)
*/
async function tp(entity) {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT,
content: `传送菜单`,
options: ['地点1', '地点2','地点3']//可改可加,加了下面也要加
})
if (selection) {
switch (selection.value) {
case '地点1':
entity.position.set(11, 45, 14)//这填坐标
break
case '地点2':
entity.position.set(19, 19, 18)//这填坐标
break
case '地点2':
entity.position.set(12, 34, 56)//这填坐标
break
}
}
}
world.onPress(async ({ entity, button }) => {//按下按键
if (button === Box3ButtonType.ACTION1) {//如果是右键
await tp(entity)//打开传送菜单
}
});
SKQA//太水了,来个简化版()
var pos=[
new Box3Vector3(),//地点1的坐标
new Box3Vector3(),//地点2
new Box3Vector3() //地点3
]
world.onPress(async({entity,button})=>{if(button!='action1')return
var result=await entity.player.dialog({type:'select',content:'传送菜单',
options:['地点1','地点2','地点3']})if(!result)return;entity.position=pos[result.index]
})点赞1
评论
array_已退建议:switch()中的
selection.value
可以改成
selection.index
它表示选中选项在option数组中的索引。这样如果改了地名也能正常传送,
点赞0
评论