Tanoda
AutoCannon.cs
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright (C) Ultraleap, Inc. 2011-2020. *
3
* *
4
* Use subject to the terms of the Apache License 2.0 available at *
5
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6
* between Ultraleap and you, your company or other organization. *
7
******************************************************************************/
8
9
using
System.Collections;
10
using
System.Collections.Generic;
11
using
UnityEngine
;
12
13
public
class
AutoCannon
: MonoBehaviour {
14
15
public
GameObject
prefab
;
16
17
public
Transform
spawnParent
;
18
public
Transform
spawnLocation
;
19
public
float
spawnSpeed
;
20
public
int
spawnPeriod
= 8;
21
public
float
lifeTime
= 1;
22
23
public
float
rotationSpeed
;
24
public
float
rotationFrequency
;
25
26
public
Queue<GameObject>
pool
=
new
Queue<GameObject>();
27
28
void
Update() {
29
transform.Rotate(0, Time.deltaTime *
rotationSpeed
* (Mathf.PerlinNoise(
rotationFrequency
* Time.time,
rotationFrequency
* Time.time * 2) - 0.5f), 0);
30
31
if
(Time.frameCount %
spawnPeriod
== 0) {
32
StartCoroutine(spawnCoroutine());
33
}
34
}
35
36
IEnumerator spawnCoroutine() {
37
GameObject obj;
38
if
(
pool
.Count > 0) {
39
obj =
pool
.Dequeue();
40
}
else
{
41
obj = Instantiate(
prefab
);
42
obj.transform.SetParent(
spawnParent
);
43
}
44
45
obj.transform.position =
spawnLocation
.position;
46
obj.transform.rotation =
spawnLocation
.rotation;
47
obj.GetComponent<Rigidbody>().velocity =
spawnLocation
.forward.normalized *
spawnSpeed
;
48
obj.SetActive(
true
);
49
50
yield
return
new
WaitForSeconds(
lifeTime
);
51
52
obj.SetActive(
false
);
53
yield
return
null
;
54
pool
.Enqueue(obj);
55
}
56
}
AutoCannon
Definition:
AutoCannon.cs:13
AutoCannon.lifeTime
float lifeTime
Definition:
AutoCannon.cs:21
AutoCannon.spawnPeriod
int spawnPeriod
Definition:
AutoCannon.cs:20
AutoCannon.pool
Queue< GameObject > pool
Definition:
AutoCannon.cs:26
AutoCannon.rotationSpeed
float rotationSpeed
Definition:
AutoCannon.cs:23
AutoCannon.spawnSpeed
float spawnSpeed
Definition:
AutoCannon.cs:19
AutoCannon.spawnParent
Transform spawnParent
Definition:
AutoCannon.cs:17
AutoCannon.spawnLocation
Transform spawnLocation
Definition:
AutoCannon.cs:18
AutoCannon.rotationFrequency
float rotationFrequency
Definition:
AutoCannon.cs:24
AutoCannon.prefab
GameObject prefab
Definition:
AutoCannon.cs:15
UnityEngine
Definition:
HSVPicker/UtilityScripts/BoxSlider.cs:7
Source
Assets
Plugins
LeapMotion
Experimental
HierarchyRecording
Examples
Cannon
AutoCannon.cs
Generated by
1.9.3