Exemplo n.º 1
0
 void Restart()
 {
     Time.timeScale = 1.0f;
     ObstacleSpeed.setSpeed(DefValues.startSpeed);
     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
Exemplo n.º 2
0
    IEnumerator SpawnObstacle()
    {
        while (true)
        {
            yield return(new WaitForSeconds(Random.Range(spawnTime, spawnTime + 0.2f)));

            //decrease spawntime until maxspawntime is reached
            if (spawnTime > DefValues.maxSpawnTime)
            {
                spawnTime = spawnTime - DefValues.decreaseSpawnTime;
            }

            //increase overall obstaclespeed if max Speed isnt reached
            if (DefValues.maxSpeed < ObstacleSpeed.getSpeed())
            {
                ObstacleSpeed.setSpeed(ObstacleSpeed.getSpeed() - DefValues.increaseSpeed);
            }

            //obstacle or item
            if (Random.value > 0.9f)
            {
                //spawn Item
                int itemNumber = (int)Random.Range(0.0f, (float)items.Length);
                SpawnItem(itemNumber);
            }
            else
            {
                //spawn Obstacle
                float random = Random.Range(0.0f, (float)obstacles.Length);

                switch ((int)random)
                {
                case 0:
                    if (random > 0.6f)
                    {
                        SpawnChocolate();
                    }
                    else
                    {
                        SpawnRock();
                    }
                    break;

                case 1:
                    SpawnRock();
                    break;

                case 2:
                    SpawnBouncing();
                    break;

                case 3:
                    //also SpawnBouncing because its on slot 4 of the obstacles (nneds a fix)
                    SpawnRock();
                    break;

                default:
                    Debug.LogError("No Obstacle with id " + (int)random);
                    break;
                }
            }
        }
        yield return(null);
    }