猫史档案馆


【岛三代码教程】如何做出玩家之间互动的效果

用户:张允旭张允旭查看:3 回复:6 评论:3 创建时间:2021-12-05T11:41:49


代码如下:

//岛三进阶教程:玩家互动
world.onPlayerJoin(({ entity }) => {
    entity.enableInteract = true //允许互动
    entity.interactRadius = 5 //互动范围
    entity.interactHint = `与${entity.player.name}互动` //提示的文字
    entity.player.showName = false //隐藏玩家的名字(不然会很奇怪)
})
world.onInteract(async ({ entity, targetEntity }) => {
    const result = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: `与${targetEntity.player.name}互动`,
        lookTarget: targetEntity,
        content: `请选择互动方式`,
        options: ['对话', '取消'],
    });
    if (result.index === 0) {
        const result1 = await entity.player.dialog({
            type: Box3DialogType.INPUT,
            title: `请输入对话内容`,
            lookTarget: entity,
            content: `请输入对话内容`,
        });
        if (result1 != null) {
            targetEntity.player.dialog({
                type: Box3DialogType.TEXT,
                title: `${entity.player.name}`,
                lookTarget: entity,
                content: result1,
            });
        }
    }
})

如果想看B站视频请看评论区


回复

上一页1 页 / 共 1下一页
张允旭张允旭

视频链接:www.bilibili.com/video/BV1vS4y1D7SJ/ 可能还在审核

点赞0


评论


DebugDynamoDebugDynamo

……

点赞0


评论


张允旭张允旭

点赞0


评论


源码极客源码极客

不错,我原先想的是用循环遍历所有玩家的方法,你这个更简单一点啊

点赞0


评论


申浩南申浩南

测试

点赞0


评论


sppXsppX

教喵++imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E8%B0%A2%E8%B0%A2%E8%80%81%E6%9D%BF.gif"alt="emotion_编程猫_谢谢老板"

点赞0


评论