-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyBehaviour.cs
More file actions
102 lines (63 loc) · 2.59 KB
/
EnemyBehaviour.cs
File metadata and controls
102 lines (63 loc) · 2.59 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
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
98
99
100
101
102
using System.Collections;
using UnityEngine;
public class EnemyBehaviour : MonoBehaviour
{
//----------------------------GAME OBJECTS -----------------------------------------------------------
public GameObject [] enemyArray;
public GameObject [] ballArray;
[SerializeField]
public GameObject GameManager;
private GameManager GameManagerScript;
[SerializeField]
private GameObject EndGamePoint;
private UpgradeSpawners upgradeSpawners;
//------------------------------VARIABLES---------------------------------------------------------------------
float screenWorldUnits2X;
float screenWorldUnits2Y;
public bool gameStarted;
int Blocks;
void Start()
{
GameManagerScript = GameManager.GetComponent<GameManager>();
gameStarted= GameManagerScript.isGameStarted;
upgradeSpawners= EndGamePoint.GetComponent<UpgradeSpawners>();
// SET THE VIEWOINT OF THE CAMERA
screenWorldUnits2X= Camera.main.aspect* Camera.main.orthographicSize-25f;
screenWorldUnits2Y= Camera.main.aspect* Camera.main.orthographicSize;
InvokeRepeating("SpawnEnemies", 3.0f, 2.0f);
InvokeRepeating("SpawnBall", 3.0f, 5.0f);
// SPAWNING THE ENEMY BLOCKS
}
void Update()
{
gameStarted= GameManagerScript.isGameStarted;
Blocks= upgradeSpawners.blocksPassed;
//Debug.Log(Blocks);
}
public void SpawnEnemies()
{
if(gameStarted)
{
int enemyIndex = Random.Range(0,4);
// TRYING TO KEEP THE BLOCKS IN SPACE
float spawnx= Random.Range(-screenWorldUnits2X, screenWorldUnits2X);
//TRYING TO MOVE THE SPAWN POSITION CLOSER
float spawny = screenWorldUnits2Y-5f;
Vector3 spawnLocation = new Vector3(spawnx, spawny, 0f);
Instantiate(enemyArray[enemyIndex],spawnLocation, Quaternion.identity);
}
}
public void SpawnBall()
{
if(gameStarted)
{
int ballIndex = Random.Range(0,2);
// TRYING TO KEEP THE BLOCKS IN SPACE
float spawnx= Random.Range(-screenWorldUnits2X, screenWorldUnits2X) - ballArray[ballIndex].transform.localScale.x;
//TRYING TO MOVE THE SPAWN POSITION CLOSER
float spawny = screenWorldUnits2Y-5f;
Vector3 spawnLocation = new Vector3(spawnx, spawny, 0f);
Instantiate(ballArray[ballIndex],spawnLocation, Quaternion.identity);
}
}
}