tolua为我们提供了一些方便开启协程的方法,让我们可以直接使用类似Unity中协程的相关方法。
比如:WaitForSeconds、Yield、WaitForFixedUpdate、WaitForEndOfFrame、Yield(异步加载返回值)等。
直接上代码
local coDelay = nil
--开启协程的方法
StartDelay = function ()
coDelay = StartCoroutine(Delay)
end
Delay = function ()
local c = 1
while true do
--可直接使用类似Unity中协程相关的方法
WaitForSeconds(1)
print("count "..c)
c = c + 1
if c > 5 then
StopDelay()
break
end
end
end
--停止协程的方法
StopDelay = function ()
StopCoroutine(coDelay)
coDelay = nil
end
StartDelay()