-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAsteroidSpawner.cs
70 lines (59 loc) · 2.29 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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AsteroidSpawner : MonoBehaviour
{
public GameObject[] AsteroidPrefabs;
public int numberOfAsteroids;
public float spawnRate = 0.5f;
void Start()
{
SpawnAsteroid();
}
#if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
private List<Texture2D> textures = new List<Texture2D>();
private void OnLowMemory()
{
Debug.Log("OnLowMemory, we have " + textures.Count + " asteroid textures!");
//Debug.LogError("trigger error");
//textures = new List<Texture2D>();
//Resources.UnloadUnusedAssets();
}
void Awake()
{
Application.lowMemory += OnLowMemory;
}
void FixedUpdate()
{
if (GameObject.FindGameObjectsWithTag("Asteroid").Length > (numberOfAsteroids/2))
{
var t = new Texture2D(1024, 1024, TextureFormat.ARGB32, true);
t.Apply();
this.textures.Add(t);
//Debug.Log("Update, we have " + this.textures.Count + " textures in here!");
}
}
#endif
void SpawnAsteroid()
{
int currentNumberOfAsteroids = GameObject.FindGameObjectsWithTag("Asteroid").Length;
if (currentNumberOfAsteroids < numberOfAsteroids)
{
var pos = ScreenBounds.RANDOM_ON_EDGE_SCREEN_LOC;
var chosenAsteroid = AsteroidPrefabs[UnityEngine.Random.Range(0, AsteroidPrefabs.Length)];
AsteraX.backtraceClient.Breadcrumbs.Info("Spawning asteroid", new Dictionary<string, string>() {
{"application.version", AsteraX.backtraceClient["application.version"]},
{"currentNumberOfAsteroids", "" + currentNumberOfAsteroids}
});
var asteroid = Instantiate(chosenAsteroid, pos, Quaternion.identity);
}
else
{
AsteraX.backtraceClient.Breadcrumbs.Info("Skipping spawning asteroid", new Dictionary<string, string>() {
{"application.version", AsteraX.backtraceClient["application.version"]},
{"currentNumberOfAsteroids", "" + currentNumberOfAsteroids}
});
}
Invoke("SpawnAsteroid", spawnRate);
}
}