代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html



一六二.萌时代(扔蜂蜜将怪物变回童年)

	用MT管理器打开游戏目录/assets/scripts/prefabs/honey.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:

local function onhit(inst, attacker, target)
	inst:Remove()
	SpawnPrefab("collapse_small").Transform:SetPosition(target.Transform:GetWorldPosition())
	target.Transform:SetScale(0.7, 0.7, 0.7)
	if target.components.health then
	   target.components.health.currenthealth = 1
	   target.components.health.maxhealth = 1
	end
	if target.components.combat then
	   target.components.combat:SetDefaultDamage(0)
	   target.components.combat.target = nil
	end
	if target.components.locomotor then
	   target.components.locomotor.runspeed = 1
	   target.components.locomotor.walkspeed = 1
	end
end
local function onthrown(inst, data)
	inst.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
end
	inst:AddComponent("weapon")
	inst.components.weapon:SetDamage(0)
	inst.components.weapon:SetRange(20, 25)
	inst:AddComponent("equippable")
	inst.components.equippable.equipstack = true
	inst:AddComponent("projectile")
	inst.components.projectile:SetSpeed(60)
	inst.components.projectile:SetOnHitFn(onhit)
	inst:ListenForEvent("onthrown", onthrown)

	即可扔蜂蜜将怪物变成无害的童年怪物,怪物体型变小、生命值为1、没有攻击力、行走缓慢。因为蜂蜜可装备,如果主角也想吃蜂蜜,请拿起蜂蜜对主角按鼠标右键