Time Tool
helloz 4/3/2024 Unity3d
unity link
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html (opens new window)
functions
functions | parameter | describe |
---|---|---|
transform:Invoke(function,float) | 1.lua function 2.delay time | delay execution of a function |
transform:InvokeRepeating(funtion,float,float) | 1.lua funtion 2. delay time 3.repeatRate | Invokes the method 'function' in time seconds, then repeatedly every repeatRate seconds. |
transform:CancelInvoke() | cancel all | |
transform:CancelInvoke(function) | 1. lua funtion | cancel function |
example: Delayed execution of functions
function Start()
print('----------start-------------')
transform:Invoke(dd,1)
transform:InvokeRepeating(Redd,1,0.5)
transform:Invoke(dd2,10)
end
function dd()
print('----------Invoke-------------')
--transform:CancelInvoke()
end
function dd2()
print('----------CancelInvoke-------------')
transform:CancelInvoke() -- cancel all
transform:CancelInvoke(Redd) -- cancel Redd function
end
function Redd()
print('----------InvokeRepeating-------------')
--transform:CancelInvoke()
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
functions 2
functions | parameter | describe |
---|---|---|
TimeTool.AddTick(object,float,function) | 1.any type, keyword 2.Intervals time 3.lua function | |
TimeTool.RemoveTick(object) | 1.any type, keyword |
example:
Start a timer to notify every second, On the fifth notification, log off the timer
count = 5
function Start()
TimeTool.AddTick(this,1,OnCall); -- 对象,时间(秒),回调
end
function OnCall()
count=count-1
print('countdown:'..tostring(count))
if count ==0 then
TimeTool.RemoveTick(this);
end
end
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12