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

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



三七二.用物品种物品

	打开游戏目录/assets/DLC0002/scripts/prefabs文件夹,其中的.lua文件为游戏中的物品。举例用木头种树精:用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/log.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:

local function OnDeploy (inst, pt)
	SpawnPrefab("leif").Transform:SetPosition(pt.x, pt.y, pt.z)
	inst.components.stackable:Get():Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy

	即可用木头种树精,将其中leif(树精)替换为其他物品,即可用木头种其他物品,物品名称见“常用物品中英文名称”。如果你用来种物品的种子物品是不可堆叠的,如牛角等,就将其中inst.components.stackable:Get():Remove()替换为inst:Remove()