我给绵月丰姬添加的一个prefab进行,modmain中除了prefab{}之外什么都没写,但读取却出错,
动画文件直接取文件里现成
local assets =
{
Asset("ANIM", "anim/yohime_sword.zip"),
Asset("ANIM", "anim/yohime_sword_swap.zip"),
Asset( "ATLAS", "images/yohime_sword.xml" ),
}
local function fn()
--生成子弹
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()
MakeInventoryPhysics(inst)
RemovePhysicsColliders(inst)
inst.Physics:SetMass(0)
inst.Transform:SetScale(2, 2, 2)
inst:AddTag("bishop_chargex")
inst:AddTag("projectile")
inst:AddTag("NOCLICK")
inst:AddTag("FX")
inst.AnimState:SetBank("yohime_sword")
inst.AnimState:SetBuild("yohime_sword")
inst.AnimState:PlayAnimation("idle")
inst:AddTag("projectile")
inst.AnimState:SetOrientation(ANIM_ORIENTATION.OnGround)
inst.AnimState:SetRayTestOnBB(true)
inst.task = nil
if not TheWorld.ismastersim then return inst end
inst.owner = nil
inst.damage = nil
inst.cannon = nil
inst.pos = nil
inst.launch = function(inst)
local x1, y1, z1 = inst:GetPosition():Get()
local x2, y2, z2 = inst.pos.x, inst.pos.y, inst.pos.z
local ydelta = math.abs(y2 - y1)
local distdelta = math.sqrt((x1 - x2) * (x1 - x2) + (z1 - z2) * (z1 - z2))
inst:ForceFacePoint(x2, y2, z2)
local speed = 20
local speed2 = distdelta
if inst.Physics.SetMotorVelOverride ~= nil
then inst.Physics:SetMass(1)
inst.Physics:SetMotorVelOverride(speed2, -speed / distdelta * ydelta / 5 * 4, 0)
end
local last_y = 99
local function stopFn(inst)
local x, y, z = inst:GetPosition():Get()
if y <= 0.1 or math.abs(y - 99) <= 0.1
then
if inst.Physics.ClearMotorVelOverride
then inst.Physics:ClearMotorVelOverride() end
inst:Hide()
end
end
inst.task:cancel
inst.task = inst:DoPeriodicTask(0.1, funtion() stopFn(inst))
inst:DoTaskInTime(5,inst.task:cancel)
end
inst.persists = false
return inst
end
return Prefab("bishop_chargex", fn, assets)