-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsteroidSpawner.cs
97 lines (87 loc) · 3.68 KB
/
AsteroidSpawner.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AsteroidSpawner : MonoBehaviour {
public static AsteroidSpawner current;
public GameObject gameView;
int spawnLocation;
public float spawnInterval;
public float spawnWait;
private void Awake()
{
current = this;
}
// Use this for initialization
void Start () {
spawnWait = spawnInterval;
StartCoroutine(SpawnAsteroids());
}
private IEnumerator SpawnAsteroids()
{
while (true)
{
spawnInterval -= 1 * Time.deltaTime;
if(spawnInterval < 0)
{
SpawnAsteroid();
spawnInterval += Random.Range(spawnWait/2,spawnWait*2);
}
yield return null;
}
}
void SpawnAsteroid()
{
GameObject obj = ObjectPooler.current.GetPooledObject();
if (obj == null) return;
spawnLocation = Random.Range(1, 5);
AsteroidProperties prop = obj.GetComponent<AsteroidProperties>();
prop.health = Mathf.RoundToInt(Random.Range(1, 4));
if(prop.health == 1)
{
obj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
}
if(prop.health == 2)
{
obj.transform.localScale = new Vector3(0.75f,0.75f,0.75f);
}
if(prop.health == 3)
{
obj.transform.localScale = new Vector3(0.9f,0.9f,0.9f);
}
/*if(spawnLocation == 1)
{
obj.transform.position += new Vector3(gameView.GetComponent<BoxCollider2D>().bounds.extents.x, gameView.GetComponent<BoxCollider2D>().bounds.extents.y);
}
else if(spawnLocation == 2)
{
obj.transform.position += new Vector3(gameView.GetComponent<BoxCollider2D>().bounds.extents.x, -gameView.GetComponent<BoxCollider2D>().bounds.extents.y);
}
else if(spawnLocation == 3)
{
obj.transform.position += new Vector3(-gameView.GetComponent<BoxCollider2D>().bounds.extents.x,gameView.GetComponent<BoxCollider2D>().bounds.extents.y);
}
else if(spawnLocation == 4)
{
obj.transform.position += new Vector3(-gameView.GetComponent<BoxCollider2D>().bounds.extents.x, -gameView.GetComponent<BoxCollider2D>().bounds.extents.y);
}*/
if(spawnLocation == 1)
{
obj.transform.position = new Vector3(gameView.GetComponent<BoxCollider2D>().bounds.extents.x, Random.Range(gameView.GetComponent<BoxCollider2D>().bounds.extents.y,-gameView.GetComponent<BoxCollider2D>().bounds.extents.y));
}
else if(spawnLocation == 2)
{
obj.transform.position = new Vector3(-gameView.GetComponent<BoxCollider2D>().bounds.extents.x, Random.Range(gameView.GetComponent<BoxCollider2D>().bounds.extents.y, -gameView.GetComponent<BoxCollider2D>().bounds.extents.y));
}
else if(spawnLocation == 3)
{
obj.transform.position = new Vector3(-gameView.GetComponent<BoxCollider2D>().bounds.extents.y, Random.Range(gameView.GetComponent<BoxCollider2D>().bounds.extents.x, gameView.GetComponent<BoxCollider2D>().bounds.extents.y));
}
else if(spawnLocation == 4)
{
obj.transform.position = new Vector3(gameView.GetComponent<BoxCollider2D>().bounds.extents.y, Random.Range(-gameView.GetComponent<BoxCollider2D>().bounds.extents.x, -gameView.GetComponent<BoxCollider2D>().bounds.extents.y));
}
obj.transform.rotation = transform.rotation;
//obj.AddComponent<AsteroidMovement>();
obj.SetActive(true);
}
}