// Start is called before the first frame update void Start() { instance = this; Vector3 spawnPosition = startPoint.position; int tilesWithNoObstaclesTmp = tilesWithoutObstacles; for (int i = 0; i < tilesToPreSpawn; i++) { spawnPosition -= tilePrefab.startPoint.localPosition; SC_PlatformTile spawnedTile = Instantiate(tilePrefab, spawnPosition, Quaternion.identity) as SC_PlatformTile; if (tilesWithNoObstaclesTmp > 0) { spawnedTile.DeactivateAllObstacles(); tilesWithNoObstaclesTmp--; } else { spawnedTile.ActivateRandomObstacle(); } spawnPosition = spawnedTile.endPoint.position; spawnedTile.transform.SetParent(transform); spawnedTiles.Add(spawnedTile); } }
// Update is called once per frame void Update() { //end the game when the song ends if (!AS.isPlaying) { gameOver = true; } // Move the object upward in world space x unit/second. //Increase speed the higher score we get if (!gameOver && gameStarted) { transform.Translate(-spawnedTiles[0].transform.right * Time.deltaTime * (movingSpeed + (score / 500)), Space.World); score += (Time.deltaTime * movingSpeed); realScore += (Time.deltaTime * (movingSpeed * bh.multiplier)); } if (mainCamera.WorldToViewportPoint(spawnedTiles[0].endPoint.position).z < 0) { //Move the tile to the front if it's behind the Camera SC_PlatformTile tileTmp = spawnedTiles[0]; spawnedTiles.RemoveAt(0); tileTmp.transform.position = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - tileTmp.startPoint.localPosition; tileTmp.ActivateRandomObstacle(); spawnedTiles.Add(tileTmp); } if (gameOver || !gameStarted) { //Start the game gameStarted = true; if (Input.GetKeyDown(KeyCode.Space)) { if (gameOver) { //Restart current scene Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name); } else { } } if (Input.GetKeyDown(KeyCode.Q)) { SceneManager.LoadScene(0); } } }
// Update is called once per frame void Update() { // Move the object upward in world space x unit/second. //Increase speed the higher score we get if (!gameOver && gameStarted) { transform.Translate(-spawnedTiles[0].transform.forward * Time.deltaTime * (movingSpeed + (score / 500)), Space.World); score += Time.deltaTime * movingSpeed; } if (mainCamera.WorldToViewportPoint(spawnedTiles[0].endPoint.position).z < 0) { //Move the tile to the front if it's behind the Camera SC_PlatformTile tileTmp = spawnedTiles[0]; spawnedTiles.RemoveAt(0); tileTmp.transform.position = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - tileTmp.startPoint.localPosition; tileTmp.ActivateRandomObstacle(); spawnedTiles.Add(tileTmp); } // if (gameOver || !gameStarted) // { // if (Input.GetKeyDown(KeyCode.Space)) // { // if (gameOver) // { // //Restart current scene // Scene scene = SceneManager.GetActiveScene(); // SceneManager.LoadScene(scene.name); // } // else // { // //Start the game // gameStarted = true; // } // } // } }