Exemple #1
0
    private void SpawnObstacle()
    {
        int           obstacleIndex;
        ObstacleStuff obstacleStuff = null;
        string        uniqueName;

        do
        {
            obstacleIndex = Random.Range(0, level.obstacles.Length);
            obstacleStuff = level.obstacles[obstacleIndex].GetComponent <ObstacleStuff>();
        } while ((obstacleStuff.uniqueName == obstacleHistory[0] && obstacleStuff.uniqueName == obstacleHistory[1]) || obstacleStuff.minSpeed > level.mainSpeed);
        obstacleHistory[obstacleHistoryIndex] = obstacleStuff.uniqueName;
        obstacleHistoryIndex = (obstacleHistoryIndex + 1) % 2;

        GameObject obstacle = (GameObject)Instantiate(level.obstacles[obstacleIndex]);

        obstacle.transform.position = new Vector3(transform.localScale.x / 2, transform.position.y, 0);
        obstacle.GetComponent <MoveRelatively>().level     = level;
        obstacle.GetComponent <DestroyOnLeftEdge>().ground = gameObject;

        float minimumSpawnDistance = obstacle.GetComponent <Collider2D>().bounds.size.x *level.mainSpeed / 4.0f + obstacle.GetComponent <ObstacleStuff>().minGap * 0.6f;

        spawnAt  = minimumSpawnDistance * (1 + Random.value * 0.5f);
        distance = 0f;
    }
Exemple #2
0
    private void SpawnObstacle()
    {
        int           obstacleIndex;
        ObstacleStuff obstacleStuff = null;

        do
        {
            obstacleIndex = Random.Range(0, level.obstacles.Length);
            obstacleStuff = level.obstacles[obstacleIndex].GetComponent <ObstacleStuff>();
        } while ((obstacleStuff.uniqueName == obstacleHistory[0] && obstacleStuff.uniqueName == obstacleHistory[1]) || obstacleStuff.minSpeed > level.mainSpeed);
        obstacleHistory[obstacleHistoryIndex] = obstacleStuff.uniqueName;
        obstacleHistoryIndex = (obstacleHistoryIndex + 1) % 2;

        GameObject obstacle = (GameObject)Instantiate(level.obstacles[obstacleIndex]);
        float      posY     = transform.position.y;

        // if(obstacle.name.Equals("ColumnOne(Clone)")) {
        //     posY = -0.66f;
        // }

        obstacle.transform.position = new Vector3(transform.localScale.x / 2, posY, 0);
        if (obstacle.name.Equals("TrickyObstacle(Clone)"))
        {
            obstacle.transform.localScale = new Vector3(RandomSide() * obstacle.transform.localScale.x, obstacle.transform.localScale.y, obstacle.transform.localScale.z);
        }
        else
        {
            obstacle.transform.localScale = new Vector3(obstacle.transform.localScale.x, RandomSide() * obstacle.transform.localScale.y, obstacle.transform.localScale.z);
        }

        obstacle.GetComponent <MoveRelatively>().level     = level;
        obstacle.GetComponent <DestroyOnLeftEdge>().ground = gameObject;

        float minimumSpawnDistance = obstacle.GetComponent <Collider2D>().bounds.size.x *level.mainSpeed / 8.0f + obstacle.GetComponent <ObstacleStuff>().minGap * 0.2f;

        spawnAt  = minimumSpawnDistance * (1 + Random.value * 0.5f);
        distance = 0f;
    }
Exemple #3
0
    private void SpawnObstacle()
    {
        int           obstacleIndex;
        ObstacleStuff obstacleStuff = null;

        do
        {
            obstacleIndex = Random.Range(0, LevelManager.Instance.m_Obstacles.Length);
            obstacleStuff = LevelManager.Instance.m_Obstacles[obstacleIndex].GetComponent <ObstacleStuff>();
        } while ((obstacleStuff.uniqueName == m_ObstacleHistory[0] && obstacleStuff.uniqueName == m_ObstacleHistory[1]) || obstacleStuff.minSpeed > LevelManager.Instance.m_MainSpeed);

        m_ObstacleHistory[m_ObstacleHistoryIndex] = obstacleStuff.uniqueName;
        m_ObstacleHistoryIndex = (m_ObstacleHistoryIndex + 1) % 2;

        GameObject obstacle = Instantiate(LevelManager.Instance.m_Obstacles[obstacleIndex]);

        obstacle.transform.position = new Vector3(transform.localScale.x / 2, transform.position.y, 0);
        obstacle.GetComponent <DestroyOnLeftEdge>().ground = gameObject;

        float minimumSpawnDistance = obstacle.GetComponent <Collider2D>().bounds.size.x *LevelManager.Instance.m_MainSpeed / 4.0f + obstacle.GetComponent <ObstacleStuff>().minGap * 0.6f;

        m_SpawnAt  = minimumSpawnDistance * (1 + Random.value * 0.5f);
        m_Distance = 0f;
    }