Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        instance = this;

        Vector3 spawnPosition = startPoint.position;

        for (int i = 0; i < tilesToPreSpawn; i++)
        {
            spawnPosition -= tilePrefab.startPoint.localPosition;
            tile spawnedTile = Instantiate(tilePrefab, spawnPosition, Quaternion.identity) as tile;
            // if(tilesWithNoObstaclesTmp > 0)
            // {
            //     spawnedTile.DeactivateAllObstacles();
            //     tilesWithNoObstaclesTmp--;
            // }
            // else
            // {
            spawnedTile.ActivateRandomObstacle();
            // }

            spawnPosition = spawnedTile.endPoint.position;
            spawnedTile.transform.SetParent(transform);
            spawnedTiles.Add(spawnedTile);
        }
    }
Ejemplo n.º 2
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


        // }
    }