写法和C#里面是一样的没啥区别 相对于C# Lua语言更加自由 没有太多的限制
require("UnityUtil")
local boy={}
function boy:OnStart()
//找到人物 给人物附上 animator 注意每个人用的框架可能不一样 需要引用一下animator
B=GameObject.Find("Boy")
B1=B:GetComponent(typeof(UnityEngine.Animator))
end
function boy:OnUpdate()
local h=Input.GetAxis("Horizontal")
local v=Input.GetAxis("Vertical")
if h~=0 or v~=0 then
local V= Vector3(h,0,v)
self.transform:LookAt(B.transform.position+V)
self.transform:Translate(V.forward*Time.deltaTime*10)
B1:SetBool("action",true)
else
B1:SetBool("action",false)
end
--按下攻击
if Input.GetKey(KeyCode.Space) then
B1:SetBool("attack",true)
else
B1:SetBool("attack",false)
end
end
return boy
使用Lua框架 会添加LuaBehaviour脚本
效果图
至于动画那块和Unity那边是一样的 大同小异