-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReModelsController.txt
More file actions
51 lines (40 loc) · 1.33 KB
/
Copy pathReModelsController.txt
File metadata and controls
51 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
behaviour("ReModelsController")
function ReModelsController:Start()
self.targetObjs = self.targets.targetObjs
self.weapon = self.targets.weapon.GetComponent(Weapon)
self.weapon.onFire.AddListener(self, "onFire")
self.cooldown = self.weapon.reloadTime
self.isCoolDown = false
self.childObjects = {}
self.currentIndex = 1
self:CollectChildObjects(self.targetObjs)
end
function ReModelsController:Update()
if self.weapon.isReloading and not self.isCoolDown then
self.script.StartCoroutine("ActivesChildObjects")
end
end
function ReModelsController:ActivesChildObjects()
self.isCoolDown = true
coroutine.yield(WaitForSeconds(self.cooldown))
for _, childObj in pairs(self.childObjects) do
childObj.SetActive(true)
end
self.isCoolDown = false
end
function ReModelsController:onFire()
local childObj = self.childObjects[self.currentIndex]
if childObj ~= nil then
childObj.SetActive(false)
self.currentIndex = self.currentIndex + 1
if self.currentIndex > #self.childObjects then
self.currentIndex = 1
end
end
end
function ReModelsController:CollectChildObjects(parentObj)
for i = 1, parentObj.transform.childCount do
local child = parentObj.transform.GetChild(i - 1).gameObject
table.insert(self.childObjects, child)
end
end