第9页:第六步代码制作(1)
展开第六步:代码制作
打开goldcoin\scripts\prefabs新建goldcoin和exchange的文本文档。
点击工具-文件夹选项-查看,去除勾选的隐藏已知文件类型的拓展名
然后把exchange和goldcoin的拓展名改为
双击打开goldcoin.lua写入
local assets=
{
Asset("ANIM", "anim/goldcoin.zip"),
Asset("ATLAS", "images/inventoryimages/goldcoin.xml"),
}
local function fn(Sim)
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
inst.entity:AddPhysics()
MakeInventoryPhysics(inst)
inst.AnimState:SetBank("goldcoin")
inst.AnimState:SetBuild("goldcoin")
inst.AnimState:PlayAnimation("idle")
inst:AddComponent("edible")
inst.components.edible.foodtype = "ELEMENTAL"
inst.components.edible.hungervalue = 2
inst:AddComponent("tradable")
inst:AddComponent("inspectable")
inst:AddComponent("stackable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.atlasname = "images/inventoryimages/goldcoin.xml"
return inst
end
return Prefab( "common/inventory/goldcoin", fn, assets)
更多相关内容请关注:饥荒专区
责任编辑:修凡客