用户:
骑士之刃查看:5 回复:3 评论:5 创建时间:2023-07-24T14:47:33
我代码有bug,代码如下:
console.clear();//懂的都懂
world.onClick(({ entity }) => {
entity.hurt(170) //被点中的实体会掉血
});
let MeshScale = [0.1, 0.1, 0.1]
global.Core = async function () {
let Core = world.createEntity({
mesh: 'mesh/喵_火史莱姆.vb',
meshScale: MeshScale,
collides: true,
fixed: true,
gravity: false,
friction: 0,
hp: 10000,
position: [63,10,喵]
})
Core.enableDamage = true;
Core.maxHp = 20000;
Core.hp = Core.maxHp;
Core.onTakeDamage(async ({ entity, attacker }) => {
global.Array = [];//定义
if (!attacker.isPlayer) return;//如果发起攻击的是玩家,不是则退出
let attackerName = attacker.player.name;//玩家名字
if (Array.includes(attackerName)) { return; };//如果在列表里就退出,否则
Array.push(attackerName);添加到列表
})
}
Core()
可是为啥报错了?图片:

萌新大佬首先,不建议定义与全局方法同名的变量
其次,attaker是需要被作为参数传入hurt函数里的,具体方式参考api
box3.yuque.com/org-wiki-box3-ev7rl4/guide/aqkg27coplqk183f#mECcB
点赞0
评论
萌新大佬是这样的
每调用一次hurt函数
就会触发一个onTakeDamage事件
而hurt函数的完整语法实际上是
entity.hurt(100, { attacker: attacker, damageType: 'damageType1'})
后项为可选
attacker则传入攻击者实体
如果不传入直接调用的话,则onTakeDamage事件中的attacker为null(damageType类似)
点赞0
评论