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

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



一八二.泡泡糖(吃黄油吹个保护泡泡)

	用MT管理器打开游戏目录/assets/scripts/prefabs/butter.lua文件,在inst.components.edible.hungervalue = TUNING.CALORIES_MED的下一行插入以下内容:

	local function proc(inst, eater)
		eater.components.health:SetInvincible(true)
		inst:AddTag("forcefield")
		local fx = SpawnPrefab("forcefieldfx")
		fx.entity:SetParent(eater.entity)
		fx.Transform:SetPosition(0, 0.2, 0)
		local fx_hitanim = function()
			fx.AnimState:PlayAnimation("hit")
			fx.AnimState:PushAnimation("idle_loop")
		end
		fx:ListenForEvent("blocked", fx_hitanim, eater)
		inst.active = true
		eater:DoTaskInTime(60, function()
			fx:RemoveEventCallback("blocked", fx_hitanim, eater)
			fx.kill_fx(fx)
			if inst:IsValid() then
				eater.components.health:SetInvincible(false)
				inst:RemoveTag("forcefield")
				eater:DoTaskInTime(5, function() inst.active = false end)
			end
		end)
	end
local function oneaten(inst, eater)
	proc(inst, eater)
end
	   	inst.components.edible:SetOnEatenFn(oneaten)

	即可吃黄油后60秒内身边环绕一个保护泡,敌人无法伤到主角。黄油可以靠杀蝴蝶掉落,也可以用本修改技巧的“栽种尖刺灌木产黄油”得到