PlaneRun/Assets/Scripts/spawner.cs

55 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawner : MonoBehaviour
{
private float timeBtwEnemySpawn;
public float startTimeEnemySpawn;
private Vector3[] spawnOffset = {new Vector3(255f,0f,0f), new Vector3(-255f,0f,0f), new Vector3(0f,0f,255f), new Vector3(0f,0f,-255f)};
private float timeBtwPickupSpawn;
public float startTimePickupSpawn;
public GameObject[] enemies;
public GameObject[] pickups;
// Start is called before the first frame update
void Start()
{
timeBtwEnemySpawn = startTimeEnemySpawn;
timeBtwPickupSpawn = startTimePickupSpawn;
}
// Update is called once per frame
void Update()
{
if(timeBtwEnemySpawn <= 0)
{
int rand = Random.Range(0, enemies.Length);
Instantiate(enemies[rand], transform.position+ spawnOffset[Random.Range(0, spawnOffset.Length)], Quaternion.identity);
timeBtwEnemySpawn = startTimeEnemySpawn;
}
else
{
timeBtwEnemySpawn -= Time.deltaTime;
}
if (timeBtwPickupSpawn <= 0)
{
int rand = Random.Range(0, pickups.Length);
Instantiate(pickups[rand], transform.position + spawnOffset[Random.Range(0, spawnOffset.Length)], Quaternion.identity);
timeBtwPickupSpawn = startTimePickupSpawn;
}
else
{
timeBtwPickupSpawn -= Time.deltaTime;
}
}
}