猫史档案馆


【岛3】求助问题

用户:小萌新金80米小萌新金80米查看:9 回复:3 评论:9 创建时间:2022-02-23T20:36:57


保持等待直到(条件成立)用代码怎么写?


回复

上一页1 页 / 共 1下一页
全能代码师全能代码师

while

点赞0


评论


yee089yee089

await吧

点赞0


评论


yee089yee089

// 先在场景中放置一个名称为 NPC 的实体。
const npc = world.querySelector('#npc');
npc.enableInteract = true;
npc.interactHint = npc.id;
npc.interactRadius = 16;

// 玩家与实体进行交互时触发
npc.onInteract(async ({entity}) => {
    const result = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: npc.id,
        lookTarget:npc,
        content: `${entity.player.name},你想尝试挑战这个游戏吗?`,
        options: ['当然', '下次吧。'],
    });

    console.log(`选择了第 index: ${result.index} 个选项: ${result.value}`)

    // 如果选了第一个选项,也就是'当然'。就会执行特定事件
    if (result.index === 0){
         npc.say(`${result.value}?那就来吧!`);
    }
});

比如这份API上的代码,其中的await entity.player.dialog({})就是类似于图形化的‘保持等待直到……’和‘询问……’,没有‘保持等待直到’(也就是JS的所谓await),对话框就会一闪而过

点赞0


评论