Hi everyone, got a question - hope someone can help. I stored 3 different prefabs into my GameObject. On Start() I set them to be false. Then I randomly turn one on at a time, in a Coroutine also found in the Start(). However, when I try to run the game, nothing shows up on the screen. Any help would be must appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
// When initializing GameObjects make sure path to prefabs are set properly
public GameObject[] moles = new GameObject[3];
// Use this for initialization
void Start () {
//moles = Resources.LoadAll("Enemy") as GameObject[];
foreach (GameObject i in moles)
{
i.SetActive(false);
}
StartCoroutine(Gameloop());
}
IEnumerator Gameloop()
{
yield return new WaitForSeconds(1f);
yield return StartCoroutine(RandomMoleSpawn());
yield return StartCoroutine(EndSequence());
}
//Mole generator...
private IEnumerator RandomMoleSpawn()
{
int loop = 0;
//My infinite loop...
while (loop < 1)
{
int Index = Random.Range(0, moles.Length);
moles[0].SetActive(OnOff());
yield return new WaitForSeconds(0.5f);
}
}
//The ON and OFF switch for my moles...
public bool OnOff()
{
int Index = Random.Range(0, 3);
if (Index > 0)
{
return true;
}
else
{
return false;
}
}
private IEnumerator EndSequence()
{
Reset();
Debug.Log("Finished!");
yield return new WaitForSeconds(1f);
}
//Returns everything back to original state...
public void Reset()
{
foreach (GameObject i in moles)
{
i.SetActive(false);
}
}
// Update is called once per frame
void Update () {
}
}