Esempio n. 1
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 (!scene.gameOver && scene.gameStarted && !scene.pause)
        {
            int speedrate = (scene.score / 50 + 1);
            speedrate = speedrate >= 0?(scene.score / 50 + 1):1;

            transform.Translate(-spawnedTiles[0].transform.forward * Time.deltaTime * (scene.movingSpeed * speedrate), 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
            tile tileTmp = spawnedTiles[0];
            spawnedTiles.RemoveAt(0);
            tileTmp.transform.position = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - tileTmp.startPoint.localPosition;
            tileTmp.ActivateAllObstacles();
            tileTmp.ActivateRandomObstacle();
            // tileTmp.ActivateRandomObstacle();
            // tileTmp.ActivateRandomObstacle();
            spawnedTiles.Add(tileTmp);
        }

        if (scene.health < 0)
        {
            scene.gameOver = true;
        }
        // if (scene.gameOver || !scene.gameStarted)
        // {
        //     if (Input.GetKeyDown(KeyCode.S))
        //     {
        //         if (scene.gameOver)
        //         {
        //             //Restart current scene
        //             Scene scene = SceneManager.GetActiveScene();
        //             SceneManager.LoadScene(scene.name);
        //         }
        //         else
        //         {
        //Start the game


        // }
    }