用户:
fomq查看:0 回复:5 评论:0 创建时间:2021-04-22T20:23:24
欢迎来到第二期的 皮卡代码教程 !
玩家互动代码:
world.onPlayerJoin(({ entity }) => {
entity.player.message1 = "";
entity.player.interactTimes = 0;
entity.enableInteract = true;
entity.interactRadius = 3;
entity.interactHint = "与 " + entity.player.name + " 互动";
entity.onInteract(async ({ entity, targetEntity }) => {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: targetEntity.player.name,
content: `和 ${targetEntity.player.name} 互动`,
options: ['和TA私聊','退出互动'], // 将提供玩家选择的选项放入数组里。
})
// 如果玩家点击了屏幕其他区域,取消了对话框。
if (!result || result === null) {
entity.player.directMessage('已为你自动取消互动!');
return;
}
if (result.index == 0) {
const dialog = await entity.player.dialog({
type: Box3DialogType.INPUT,
title: "向 "+targetEntity.player.name+" 发送私聊信息",
content: `${entity.player.name},请输入私聊内容`,
confirmText: '发送', // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: '请输入私聊内容', // 输入框背景上的提示文字。
});
targetEntity.player.message1 = dialog;
targetEntity.player.directMessage('收到 '+entity.player.name+' 向你发送的私聊信息,正在为你打开查看……')
await sleep(2000);
targetEntity.player.directMessage('正在查收 '+entity.player.name+" 发送的私聊信息")
entity.player.directMessage('对方已收到聊天信息')
if (dialog) {
const dialog = targetEntity.player.dialog({
type: Box3DialogType.TEXT,
title: entity.player.name, // 对话框标题。通常对应是讲话人的名字。
content: targetEntity.player.message1, // 对话框内容。也就是对话正在讲什么。
});
}
}
})
})
与实体互动:
const npc = world.querySelector('#车');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 5; // 实体的互动范围
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},欢迎来到博物馆!`,
});
});
本期教程到此结束!
FML饭米粒 entity.onInteract(async ({ entity, targetEntity }) => {
已经有了entity,再弄个targetEntity感觉有些多余啊
点赞0
评论