用户:
kessice查看:0 回复:0 评论:0 创建时间:2022-12-08T08:22:17
他为什么报错
// 先在场景中放置一个名称为 NPC 的实体。
/*
const npc = world.querySelector('#圣诞老人');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 16; // 实体的互动范围
npc.interactHint = npc.id; // 互动提示框显示实体的名称
npc.interactColor = new Box3RGBColor(1,0,1); // 互动提示的文字颜色
// 玩家与实体进行交互时触发
npc.onInteract(async({entity}) => {
const result = await entity.player.dialog({
type: Box3DialogType.TEXT, // 对话框的类型,TEXT是文本框。
title: npc.id, // 对话框标题为NPC名字,表示正在说话的是NPC
lookEye: entity, // 将相机放在玩家位置
lookTarget: npc, // 相机镜头对准NPC
content: `你好,${entity.player.name},很高兴认识你。这里开始了一年一度的圣诞大赛,你要参加吗?只有成功的人才能获得无上的荣誉!!!`,
});
});
*/
for (const e of world.querySelectorAll('*')) {//遍历所有实体
if (e.id.startsWith('方块')) {//如果当前实体名左边部分刚好是"存档点", 比如 存档点-1 存档点-2...
e.onEntityContact(({ other }) => { //每当存档点碰到另一个实体
if (other.isPlayer) { //另一个实体是玩家
other.player.directMessage('这是创作者出入的地方,请不要穿越!!!') // 给玩家发消息
}
})
}
}
let ren = 0
const npc = world.querySelector('#圣诞老人');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 4; // 实体的互动范围
npc.interactHint = npc.id; // 互动提示框显示实体的名称
npc.interactColor = new Box3RGBColor(1,1,1); // 互动提示的文字颜色
npc.onInteract(async({entity}) => {
const result = await entity.player.dialog({
type:'select',
text:'',
content:`你好,${entity.player.name},很高兴认识你。这里开始了一年一度的圣诞奥运会,你要参加吗?只有成功的人才能获得无上的荣誉!!!`,
options:['去','不去']
})
// 如果玩家点击了屏幕其他区域,取消了对话框。
if(!result || result === null){
entity.player.directMessage('你无视了圣诞老人');
return;
}
if(result.index == 0){
entity.player.directMessage(`好的`);
len += 1
entity.position.set(4,14,17)
}
});
console.clear()