GlobalGameJame/Assets/Scripts/SpawnManager.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2020-02-01 15:29:20 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public List<GameObject> enemyList = new List<GameObject>();
public List<Transform> spawnPoints = new List<Transform>();
2020-02-01 19:58:47 +00:00
public int enemyStartNumber = 5;
2020-02-02 07:36:26 +00:00
public GameObject Sun;
2020-02-01 16:51:30 +00:00
2020-02-01 19:58:47 +00:00
2020-02-01 16:51:30 +00:00
bool night = false;
bool alreadySpawn = false;
2020-02-01 15:29:20 +00:00
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
2020-02-01 19:58:47 +00:00
int enemyNumber = enemyStartNumber + (Sun.GetComponent<DayManager>().daySurvived * enemyStartNumber);
2020-02-01 16:51:30 +00:00
float sunRotationX = Sun.transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
if (sunRotationX < 0)
{
night = true;
} else {
night = false;
}
2020-02-01 15:29:20 +00:00
2020-02-01 16:51:30 +00:00
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;
2020-02-01 15:29:20 +00:00
}
}