// Spawn the answer private IEnumerator SpawnAnswer() { Debug.Log("Random spawn answer started"); while (true) { if (Mathf.RoundToInt(_timerManager.Seconds) == 5 || Mathf.RoundToInt(_timerManager.Seconds) == 7) { GameObject spawnedPrefab = Instantiate( _numberPrefab, // Top screen + offset to offscreen the prefabs instantiation new Vector3(Random.Range(-_screenBounds.x + 0.5f, _screenBounds.x - 0.5f), _screenBounds.y + 0.5f, 0f), Quaternion.identity); int answer = int.Parse(_questionList[_questionIdx].Answer); NumberScriptPop scriptPop = spawnedPrefab.GetComponent <NumberScriptPop>(); scriptPop.MoveSpeed = _speed; scriptPop.Content = answer.ToString(); Debug.Log("Answer spawned:" + answer); // Prevent spawning multiple time at n second yield return(new WaitForSeconds(1)); } yield return(null); } }
// Spawn random answers and resets time private IEnumerator RandomSpawn() { Debug.Log("Random spawn started"); while (true) { GameObject spawnedPrefab = Instantiate( _numberPrefab, new Vector3(Random.Range(-_screenBounds.x + 0.5f, _screenBounds.x - 0.5f), _screenBounds.y + 0.5f, 0f), Quaternion.identity); int answer = int.Parse(_questionList[_questionIdx].Answer); NumberScriptPop scriptPop = spawnedPrefab.GetComponent <NumberScriptPop>(); scriptPop.MoveSpeed = _speed; scriptPop.Content = Random.Range(answer - 5, answer + 5).ToString(); yield return(new WaitForSeconds(_spawnRate)); } }