private void Update() { //update score if player pass obstacle if (transform.position.z < 0 && !obstaclePassed) { if (obstacle != null) { PlayerEvents.FireScoreUp(5, true); obstaclePassed = true; } } }
private void Update() { if (moving) { //Count flying time with/without boost if (IsBoostedSpeed()) { timeBoostSpeed += Time.deltaTime; } else { timeBoostSpeed = 0; timeNormalSpeed += Time.deltaTime; } //Update score after one second if (timeBoostSpeed >= 1) { timeBoostSpeed = 0; //fire score event PlayerEvents.FireScoreUp(2, false); } if (timeNormalSpeed >= 1) { timeNormalSpeed = 0; PlayerEvents.FireScoreUp(1, false); } //Move all tiles in List for (var i = 0; i < tiles.Count; i++) { tiles[i].Move(tilesSpeed); //if player pass tile, move it to the end of list if (tiles[i].GetZPosition() < tileDestroyCoordinate) { tiles[i].transform.position = new Vector3(0, tileHeigth, lastTile.position.z + tileLenght); tiles[i].DestroyObstacle(); lastTile = tiles[i].transform; var currentTile = tiles[i]; tiles.Remove(tiles[i]); tiles.Add(currentTile); tilesSpawned++; } } //Spawn Tile if enough time passed obstacleSpawnTime += Time.deltaTime; if (obstacleSpawnTime >= obstacleSpawnRate) { obstacleSpawnTime = 0; lastTile.GetComponent <Tile>().SpawnObstacle(asteroid); } //Change difficulty every 20 tiles if (tilesSpawned > 20) { tilesSpawned = 0; IncreaseDifficulty(); } } }