Im trying to make a Wave count display before each wave of the asteroid shooter (the tutorial game) and then dissappear after a few seconds, i have been able to get the text to appear once for the first game but once it dissappears (i use the destroyByTime script to make it dissappear) it never reappears saying that the gameobject has been destroyed but the thing is i put the GUIText in an empty gameobject naming it wavTXT and moved it to my prefabs folder.
i dont mind rewriting code
here is my code for the gameController:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gameController : MonoBehaviour {
public GameObject hazard;
public Vector3 spawnVals;
public int hazCount;
public float sWait;
public float startWait;
private int hazC;
private int waveCount = 1;
public GUIText waveTXT;
public GameObject waveUI;
public GUIText scoreTXT;
private int score;
private void Start()
{
score = 0;
updateScore();
updateWave();
StartCoroutine (spawnWaves());
}
IEnumerator spawnWaves()
{
hazC = hazCount;
while (true)
{
yield return new WaitForSeconds(startWait);
for (int i = 0; i < hazC; i++)
{
Vector3 spawnPos = new Vector3(Random.Range(-spawnVals.x, spawnVals.x), spawnVals.y, spawnVals.z);
Quaternion spawnRot = Quaternion.identity;
Instantiate(hazard, spawnPos, spawnRot);
yield return new WaitForSeconds(sWait);
}
hazC += 2;
waveCount += 1;
updateWave();
}
}
public void addScore(int newVal)
{
score += newVal;
updateScore();
}
void updateWave()
{
waveTXT.text = "Wave: " + waveCount;
waveUI = Instantiate(waveUI, Camera.main.WorldToViewportPoint(gameObject.transform.position), Quaternion.identity);
}
void updateScore()
{
scoreTXT.text = "Score: " + score;
}
}
Here is my DestroyByTime code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class timeDestroyer : MonoBehaviour {
public float lifeTime;
// Use this for initialization
void Start () {
Destroy(gameObject, lifeTime);
}
}