forked from nuwud/Unity_Kinect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectDropper.cs
More file actions
50 lines (43 loc) · 1.24 KB
/
Copy pathObjectDropper.cs
File metadata and controls
50 lines (43 loc) · 1.24 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
using UnityEngine;
using System.Collections;
public class ObjectDropper : MonoBehaviour
{
public GameObject[] objects;
public float fireRate;
public float spawnWidth;
private Transform tr;
private float seconds;
void Start()
{
// get local components
tr = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
// instantiates our objects
Spawn(fireRate);
}
void Spawn(float rate)
{
// timer, adds up the delta time for seconds
seconds += Time.deltaTime;
// if seconds great than our rate as defined in the inspector
if (seconds > rate)
{
// random x position
float randomX = Random.Range(-spawnWidth, spawnWidth);
Vector3 position = new Vector3
(
tr.position.x + randomX,
tr.position.y,
tr.position.z
);
// randomly select an object in the danger array
int randomObj = Random.Range(0, objects.Length);
Instantiate(objects[randomObj], position, transform.rotation);
// zero out the seconds variable
seconds = 0;
}
}
}