private IEnumerator RemoveCookie(float waitTime) { yield return new WaitForSeconds(waitTime); if (isGameRunning) { Destroy(activeCookie.gameObject); activeCookie = null; ScheduleCookieSpawn(); } }
private IEnumerator SpawnCookie(float waitTime) { yield return new WaitForSeconds(waitTime); if (isGameRunning) { activeCookie = Instantiate(cookie).GetComponent<SpeedCookie>(); activeCookie.touched += HandleSpeedCookieTouched; int spawnPointIndex = Random.Range(0, settings.cookieSpawnPoints.Count); activeCookie.transform.position = settings.cookieSpawnPoints[spawnPointIndex]; StartCoroutine(RemoveCookie(settings.cookieTimeLimit)); } }