Random Spawn Manager
This commit is contained in:
parent
b3e77ab1c3
commit
428caf87d0
@ -7,6 +7,11 @@ public class SpawnManager : MonoBehaviour
|
||||
|
||||
public List<GameObject> enemyList = new List<GameObject>();
|
||||
public List<Transform> spawnPoints = new List<Transform>();
|
||||
public int enemyNumber = 10;
|
||||
public GameObject Sun = new GameObject();
|
||||
|
||||
bool night = false;
|
||||
bool alreadySpawn = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@ -17,6 +22,46 @@ public class SpawnManager : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
float sunRotationX = Sun.transform.localEulerAngles.x;
|
||||
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
|
||||
|
||||
Debug.Log(sunRotationX.ToString());
|
||||
if (sunRotationX < 0)
|
||||
{
|
||||
Debug.Log("It is a Night");
|
||||
night = true;
|
||||
} else {
|
||||
Debug.Log("It is a Day");
|
||||
night = false;
|
||||
}
|
||||
|
||||
|
||||
if (!night)
|
||||
{
|
||||
alreadySpawn = false;
|
||||
}
|
||||
|
||||
if (!alreadySpawn && night)
|
||||
{
|
||||
for (int i = 0; i < enemyNumber; i++)
|
||||
{
|
||||
int randomSpawnPoint = Random.Range(0, (spawnPoints.Count - 1));
|
||||
int random = Random.Range(0, (enemyList.Count - 1));
|
||||
GameObject randomSpawnPointGO = spawnPoints[randomSpawnPoint].gameObject;
|
||||
|
||||
Instantiate(enemyList[random], new Vector3(randomSpawnPointGO.transform.position.x, randomSpawnPointGO.transform.position.y, randomSpawnPointGO.transform.position.z), Quaternion.identity);
|
||||
alreadySpawn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float Clamp0360(float eulerAngles)
|
||||
{
|
||||
float result = eulerAngles - Mathf.CeilToInt(eulerAngles / 360f) * 360f;
|
||||
if (result < 0)
|
||||
{
|
||||
result += 360f;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user