用户:
云游de军长渡查看:0 回复:2 评论:0 创建时间:2022-08-25T11:43:23
现在我们来做最后一个彩蛋代码。这个代码比较简单一点
粒子特效
//给里面放一个名叫 彩蛋-3的npc
////给第二个npc 使用时,里面的 npc4 要更改,更改成啥没要求,但是要更换成统一的字母/数字
const npc4 = world.querySelector('#彩蛋-3');
npc4.enableInteract = true; // 允许进行互动
npc4.interactRadius = 2; // 实体的互动范围
npc4.interactHint = npc4.id; // 互动提示框显示实体的名称
npc4.interactColor = new Box3RGBColor(1,1,1); // 互动提示的文字颜色
// 玩家与实体进行交互时触发
npc4.onInteract(async({entity}) => {
const result = await entity.player.dialog({
type: Box3DialogType.TEXT, // 对话框的类型,TEXT是文本框。
title: npc4.id, // 对话框标题为NPC名字,表示正在说话的是NPC
lookEye: entity, // 将相机放在玩家位置
lookTarget: npc4, // 相机镜头对准NPC
content: `${entity.player.name},恭喜你找到彩蛋-3,粒子特效`,
});
});
const egg = world.querySelector('#彩蛋-3');
egg.enableInteract = true;
egg.interactHint = '彩蛋-3';
egg.interactRadius = 2;
function rgb(r, g, b) {
return new Box3RGBColor(r / 255, g / 255, b / 255);
}
egg.onInteract(async ({ entity }) => {
Object.assign(entity, {
particleRate: 200,
particleSize: 3,
particleColor: [
new rgb(252, 75, 10),
new rgb(255, 231, 7),
new rgb(200, 252, 10),
new rgb(12, 156, 242),
new rgb(242, 12, 165),
],
particleLifetime: 2,
particleVelocitySpread: new Box3Vector3(1, 1, 1),
});
});