// Update is called once per frame void Update() { time += Time.deltaTime; lastCreationTime += Time.deltaTime; if ((int)time % spawnFrequency == 0 && lastCreationTime > spawnFrequency) { lastCreationTime = 0; GameObject coin = coinsPooler.getObject(); if (coin == null) { return; } float yPos = 1.5f; float xPos = Random.Range(-boardWidth, boardWidth); float zPos = Random.Range(-boardWidth, boardWidth); coin.transform.position = new Vector3(xPos, yPos, zPos); coin.SetActive(true); } }
// Update is called once per frame void Update() { time += Time.deltaTime; lastCreationTime += Time.deltaTime; if ((Time.realtimeSinceStartup - lastUpdateTime) > timeBetweenUpdates) { timeBetweenUpdates += 0.1f; lastUpdateTime = Time.realtimeSinceStartup; if (spawnFrequency > 0.5f) { spawnFrequency = spawnFrequency - 0.2f; } if (EnemyController.speed < 15f) { EnemyController.speed = EnemyController.speed + 0.4f; } } if (lastCreationTime > spawnFrequency) { lastCreationTime = 0; GameObject enemy = enemiesPooler.getObject(); if (enemy == null) { return; } Vector3 newPos = new Vector3(Random.Range(-boardWidth, boardWidth), 1.5f, Random.Range(-boardWidth, boardWidth)); while ((newPos - player.transform.position).magnitude < 10f) { newPos = new Vector3(Random.Range(-boardWidth, boardWidth), 1.5f, Random.Range(-boardWidth, boardWidth)); } enemy.transform.position = newPos; enemy.SetActive(true); Vector3 playerPosition = player.transform.position; enemy.GetComponent <EnemyController>().SetPlayerPosition(playerPosition); } }