168 lines
6.4 KiB
C#
168 lines
6.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WaveManager : MonoBehaviour
|
|
{
|
|
[Header("Wave 1 (civil cars)")]
|
|
public GameObject civilCar;
|
|
public float CivilCarSpawnDelay;
|
|
public int CivilCarsAmout;
|
|
|
|
[Header("Wave 2 (PoliceBomb cars)")]
|
|
public GameObject PoliceBombCar;
|
|
public int bombsAmount;
|
|
public int policecarVerticalSpeed;
|
|
public int policecarHorizontalSpeed;
|
|
public float bombDelay;
|
|
private GameObject spawnedPoliceBombCar;
|
|
private bool isSpawned;
|
|
private bool is2ndSpawned;
|
|
[Header("Wave 3 (PoliceB cars)")]
|
|
public GameObject PoliceCarB;
|
|
public int PoliceCarBAmount;
|
|
[HideInInspector]
|
|
static public bool isLeft;
|
|
[HideInInspector]
|
|
static public bool isRight;
|
|
public float shootingSeriesDelay;
|
|
public float singleShotDelay;
|
|
public float policeCarBVerticalSpeed;
|
|
public int bulletsInSeries;
|
|
private GameObject spawnedPoliceCarB;
|
|
[Header("Points")]
|
|
public int pointsPerCivilCar;
|
|
public int pointsPerPoliceBombCar;
|
|
public int pointsPerBomb;
|
|
public int pointsPerPoliceBCar;
|
|
|
|
public GameObject EndGameScreen;
|
|
|
|
private float[] lanesArray;
|
|
private float spawnDelay;
|
|
|
|
void Start()
|
|
{
|
|
lanesArray = new float[4];
|
|
lanesArray[0] = -2.13f;
|
|
lanesArray[1] = -0.76f;
|
|
lanesArray[2] = 0.76f;
|
|
lanesArray[3] = 2.13f;
|
|
spawnDelay = CivilCarSpawnDelay;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
spawnDelay -= Time.deltaTime;
|
|
if (spawnDelay <= 0 && CivilCarsAmout > 0)
|
|
{
|
|
SpawnCar();
|
|
spawnDelay = CivilCarSpawnDelay;
|
|
|
|
} else if (CivilCarsAmout <= 0 && is2ndSpawned == false)
|
|
{
|
|
if(isSpawned == false)
|
|
{
|
|
spawnPoliceBombCar();
|
|
} else if(isSpawned == true && spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().bombsAmount < 10 && is2ndSpawned == false)
|
|
{
|
|
spawnPoliceBombCar();
|
|
}
|
|
|
|
} else if (CivilCarsAmout <= 0 && PoliceCarBAmount > 0 && spawnedPoliceBombCar == null)
|
|
{
|
|
spawnPoliceCarB();
|
|
} else if(PoliceCarBAmount <= 0 && isLeft == false && isRight == false)
|
|
{
|
|
//Time.timeScale = 0;
|
|
EndGameScreen.SetActive(true);
|
|
}
|
|
}
|
|
|
|
void spawnPoliceCarB()
|
|
{
|
|
Transform playerCarPosition;
|
|
if(GameObject.FindWithTag("Player"))
|
|
{
|
|
playerCarPosition = GameObject.FindWithTag("Player").transform;
|
|
}else if(GameObject.FindWithTag("Shield"))
|
|
{
|
|
playerCarPosition = GameObject.FindWithTag("Shield").transform;
|
|
}else if(GameObject.FindWithTag("Untouchable"))
|
|
{
|
|
playerCarPosition = GameObject.FindWithTag("Untouchable").transform;
|
|
} else
|
|
{
|
|
playerCarPosition = null;
|
|
}
|
|
if(playerCarPosition.position.x <= -0.2f && isRight == false)
|
|
{
|
|
spawnedPoliceCarB = (GameObject)Instantiate(PoliceCarB, new Vector3(2.25f, -6f, 0), Quaternion.identity);
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().isLeft = false;
|
|
isRight = true;
|
|
PoliceCarBAmount--;
|
|
} else if(playerCarPosition.position.x > -0.2f && isLeft == false)
|
|
{
|
|
spawnedPoliceCarB = (GameObject)Instantiate(PoliceCarB, new Vector3(-2.25f, -6f, 0), Quaternion.identity);
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().isLeft = true;
|
|
isLeft = true;
|
|
PoliceCarBAmount--;
|
|
}
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().shootingSeriesDelay = shootingSeriesDelay;
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().singleShotDelay = singleShotDelay;
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().policeCarBVerticalSpeed = policeCarBVerticalSpeed;
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().bulletsInSeries = bulletsInSeries;
|
|
spawnedPoliceCarB.GetComponent<PoliceCarBBehaviour>().pointsPerCar = pointsPerPoliceBCar;
|
|
|
|
|
|
|
|
}
|
|
|
|
void spawnPoliceBombCar()
|
|
{
|
|
if (isSpawned == false)
|
|
{
|
|
spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(Random.Range(-2.3f, 2.3f), 7f, 0), Quaternion.identity);
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().bombDelay = bombDelay;
|
|
isSpawned = true;
|
|
} else if (isSpawned == true && is2ndSpawned == false)
|
|
{
|
|
if (spawnedPoliceBombCar.transform.position.x < 0.5f)
|
|
{
|
|
spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(2.2f, 7f, 0), Quaternion.identity);
|
|
is2ndSpawned = true;
|
|
} else if (spawnedPoliceBombCar.transform.position.x >= 0.5f)
|
|
{
|
|
spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(-2.2f, 7f, 0), Quaternion.identity);
|
|
is2ndSpawned = true;
|
|
}
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().bombDelay = bombDelay / 1.5f;
|
|
}
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().bombsAmount = bombsAmount;
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().policecarVerticalSpeed = policecarVerticalSpeed;
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().policecarHorizontalSpeed = policecarHorizontalSpeed;
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().pointsPerCar = pointsPerPoliceBombCar;
|
|
spawnedPoliceBombCar.GetComponent<PoliceBombBehavioru>().bomb.GetComponent<Bomb>().pointsPerBomb = pointsPerBomb;
|
|
}
|
|
|
|
void SpawnCar()
|
|
{
|
|
int lane = Random.Range(0, 4);
|
|
if (lane == 0 || lane == 1)
|
|
{
|
|
GameObject car = (GameObject)Instantiate(civilCar, new Vector3(lanesArray[lane], 6f, 0), Quaternion.Euler(new Vector3(0, 0, 180)));
|
|
car.GetComponent<CivilCarBehaviour>().direction = 1;
|
|
car.GetComponent<CivilCarBehaviour>().civilCarSpeed = 9f;
|
|
car.GetComponent<CivilCarBehaviour>().pointsPerCar = pointsPerCivilCar;
|
|
}
|
|
|
|
if (lane == 2 || lane == 3)
|
|
{
|
|
GameObject car = (GameObject)Instantiate(civilCar, new Vector3(lanesArray[lane], 6f, 0), Quaternion.identity);
|
|
car.GetComponent<CivilCarBehaviour>().pointsPerCar = pointsPerCivilCar;
|
|
}
|
|
CivilCarsAmout--;
|
|
}
|
|
|
|
}
|