用户:
AK亨利佐加DanJamesThomas查看:0 回复:2 评论:0 创建时间:2022-11-14T08:36:27
嗯,最近合作的几个图,我看到互动代码时,只能说
const npc1=world.querySelector("#something");
npc1.enableInteract=true;
npc1.interactHint="something";
npc1.interactRadius=3;
npc1.onInteract(({entity})=>{
/**something for the entity */
})
const npc2=world.querySelector("#something2");
npc2.enableInteract=true;
npc2.interactHint="something";
npc2.interactRadius=3;
npc2.onInteract(({entity})=>{
/**something for the entity */
})
const npc3=world.querySelector("#something3");
npc3.enableInteract=true;
npc3.interactHint="something";
npc3.interactRadius=3;
npc3.onInteract(({entity})=>{
/**something for the entity */
})
吃了没文化的亏!
看看我这简单至“极”的互动代码!
首先,给每个实体加一下标签“interactive”,表示它能互动,然后给每个可互动体给予可互动的代码
for (var target of world.querySelectorAll('.interactive')) {
target.enableInteract = true;
target.interactRadius = 4; // 实体的互动范围
if (target.hasTag('o_people')) {
target.interactHint = '村民'
}
else if (target.hasTag('sell')) {
target.interactHint = sell_name[target.id]; // 互动提示框显示实体的名称
}
else {
target.interactHint = target.id; // 互动提示框显示实体的名称
}
if (target.hasTag('lift')) {
target.interactColor.set(0, 0, 1)
}
else if (target.hasTag('oven')) {
target.interactHint = '烤制'; // 互动提示框显示实体的名称
target.interactRadius = 2; // 实体的互动范围
}
}
嗯,对了还有一点,就是得把每个实体加上个表示它是什么东西的标签。
然后如何判断互动?
world.onInteract(async ({ entity, targetEntity }) => {})
world是喵的!
注意:entity是所互动的玩家,targetEntity是被互动的实体!
好啦,根据每个实体的标签给予代码就可以啦!
(完)
AK亨利佐加DanJamesThomas第一期:shequ.codemao.cn/community/499259
第二期:shequ.codemao.cn/community/499269
点赞0
评论