- Home /
Having trouble increasing the spawning speed of explosions
Hello, I've been trying to make a game where waves of explosions spawn (game object with a sprites, with a trigger box collider that kills the player), the box collider quickly fade away with the sprites, and then the next wave spawn next to the first one, making a linear pattern (1st level). The thing is, I got it all working perfectly, the wave goes from right to left and then left to right, but I cant seem to find a working system to increase the spawning rate. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoardManager : MonoBehaviour
{
public GameObject timerUI;
public int rows = 8;
public int columns = 8;
public GameObject wallTiles;
public GameObject[] floorTiles;
public GameObject watertiles;
public GameObject player;
public GameObject keyPrefab;
bool playerDead = false;
public float levelSpeed = 0f;
public float levelSpeedIncreaser = 0.90f;
public float intervalSpeed = 2;
bool waveDone = false;
bool waveDeleteDone = false;
bool level1Started = false;
bool increasing = false;
int x = 8;
int spawnCount = 1;
public Destroyobjects destroyScript;
public float timer;
public int level1StartTime = 5;
GameObject key;
private Transform boardHolder;
private Transform obstaclesHolder;
// Use this for initialization
void Start()
{
boardHolder = new GameObject("Board").transform;
obstaclesHolder = new GameObject("Obstacles").transform;
for (int x = 0; x < columns + 2; x++)
{
for (int y = 0; y < rows + 2; y++)
{
GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
if (x == 0 || y == 0 || x == columns + 1 || y == rows + 1)
{
toInstantiate = wallTiles;
}
GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
instance.transform.SetParent(boardHolder);
}
}
Instantiate(keyPrefab, new Vector3(Random.Range(2, columns), Random.Range(2, rows), 0), Quaternion.identity);
}
// Update is called once per frame
void Update()
{
timer = timerUI.GetComponent<Timer>().timerf;
if (timer >= level1StartTime && !waveDone)
{
waveDone = true;
waveDeleteDone = false;
for (int y = 1; y <= rows; y++)
{
GameObject water = Instantiate(watertiles, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
water.transform.SetParent(obstaclesHolder);
}
}
if (!waveDeleteDone)
{
if (timer >= intervalSpeed * spawnCount + level1StartTime - levelSpeed) //My attempt at increasing the speed
{
print("condition met");
waveDeleteDone = true;
destroyScript.DestroyObjects("Water");
if (!increasing)
{
if (x == 1)
{
x++;
increasing = true;
levelSpeed -= 0.01f * spawnCount; // my attempt at increasing the speed
}
else
{
x--;
}
}
else
{
if (x == 8)
{
x--;
increasing = false;
}
else
{
x++;
}
}
spawnCount++;
waveDone = false;
}
}
}
}
There must be a problem with how I keep track of time, I would like to reset my timer (that counts seconds since awake) to zero every time a wave spawns, and then respawn one at next location with a SMALLER interval of time. How can I do that? Been workingf on that problem for a few hours... figured I'd ask here for help!
I tried reducing the interval time with this structure, but sometimes I would spawn 2 waves in a row since i'm using Seconds since awake.
Thank you for your help, i am new to programming as you probably noticed -_-
Your answer
Follow this Question
Related Questions
Time.DeltaTime doesn't seem to be correctly 1 Answer
How to make this display milliseconds? 3 Answers
Multiple Cars not working 1 Answer
Is there any way to determine Unity's actual target frame rate? 1 Answer
Distribute terrain in zones 3 Answers