Points unity coroutine

Use coroutine timing is to be noted that functions
1 coroutine components used, and other variables are set to an unprecedented, should be blank coroutine
should stop before coroutine 2. blanking coroutine
3. In order to ensure the same while a coroutine run only once, may be added before the start coroutine security code: determining whether there is a change coroutine, and coroutine presence coroutine blanking stop
method:

local function setMyTime()
    --注意(3)
    if this.countdown then
        coroutine.stop(this.countdown)
        this.countdown = nil
    end
    this.countdown = coroutine.start(function()
        while true do
            this.tm=this.tm-1--用到的变量
            coroutine.wait(1)
        end
    end)
end
注意(2)
if this.countdown then
    coroutine.stop(this.countdown)
    --注意(1)
    this.countdown = nil
end
--假设此时需要对this.tm置空
this.tm=nil

Guess you like

Origin www.cnblogs.com/shirln/p/11799719.html