Example #1
0
    public void GenerateObstacles()
    {
        System.Random random   = new System.Random();
        GameObject    obstacle = null;
        float         left     = -2.6f;
        float         right    = 2.6f;

        for (int i = 1; i <= Persistance.GetObstaclesNumber(); i++)
        {
            Vector3 obstaclePosition = new Vector3((float)random.NextDouble() * (right - left) + left, 0f, gapLength * i);
            obstacle = Instantiate(obstaclePrefab, obstacleBasis.position + obstaclePosition, obstacleBasis.rotation) as GameObject;
        }

        if (obstacle != null)
        {
            float raceLength = obstacle.transform.position.z + gapLength;

            transformFinish.position += new Vector3(0f, 0f, raceLength);
        }
    }