Пример #1
0
    void SpawnTerrain()
    {
        // Spawn terrain
        int numSegments = Random.Range(minContiguousTerrainSegments, maxContiguousTerrainSegments);
        int totalWidth  = 0; // measured in # tiles

        int             currentSequenceWidth    = 0;
        int             heightOfCurrentSequence = 0;
        TerrainRenderer firstSegment            = null;

        for (int x = 0; x < numSegments; x++)
        {
            int segmentWidth  = Random.Range(minTerrainSegmentWidth, maxTerrainSegmentWidth);
            int segmentHeight = Random.Range(minTerrainSegmentHeight, maxTerrainSegmentHeight);

            float terrainSegmentX = transform.position.x + totalWidth;
            float terrainSegmentY = cameraLowerEdge;

            TerrainRenderer currentSegment = base.SpawnTerrain(terrainSegmentX, terrainSegmentY, segmentWidth, segmentHeight);

            if (x == 0)
            {
                firstSegment = currentSegment;
            }
            else if (segmentHeight != heightOfCurrentSequence)
            {
                firstSegment.ConfigureCollider(currentSequenceWidth, heightOfCurrentSequence);
                firstSegment         = currentSegment;
                currentSequenceWidth = 0;
            }

            if (x == numSegments - 1)
            {
                if (segmentHeight == heightOfCurrentSequence)
                {
                    firstSegment.ConfigureCollider(currentSequenceWidth + segmentWidth, heightOfCurrentSequence);
                }
                else
                {
                    currentSegment.ConfigureCollider(segmentWidth, segmentHeight);
                }
            }

            currentSequenceWidth   += segmentWidth;
            heightOfCurrentSequence = segmentHeight;

            // Spawn obstacle in random location on top of terrain segment
            float minObstacleX = terrainSegmentX;
            float maxObstacleX = terrainSegmentX + segmentWidth;
            float minObstacleY = terrainSegmentY + segmentHeight + 0.5f;

            SpawnObject(minObstacleX, maxObstacleX, minObstacleY);

            totalWidth += segmentWidth;
        }

        // Schedule next spawn
        Invoke("SpawnNext", (totalWidth * TerrainRenderer.TerrainTileUnit) / GameSettings.Instance.GameSpeed
               + Random.Range(minSpawnWaitTime, maxSpawnWaitTime));
    }
Пример #2
0
    void Start()
    {
        PhotonNetwork.OnEventCall += this.OnEvent;

        if (GameSettings.Instance.MultiplayerMode)
        {
            Vector2 lowerLeftCorner = Camera.main.ViewportToWorldPoint(new Vector3(0, 0));
            // Camera width = orthographicSize * aspect * 2. Add 4 to account for helper's spawner offset.
            int             width   = (int)(Camera.main.orthographicSize * Camera.main.aspect * 2 + distanceOffset + 4);
            TerrainRenderer terrain = base.SpawnTerrain(lowerLeftCorner.x, lowerLeftCorner.y, width, startingTerrainHeight);
            terrain.ConfigureCollider(width, startingTerrainHeight);
        }
    }
Пример #3
0
    void SpawnTerrain(Vector2 pos, int width, int height)
    {
        TerrainRenderer terrain = base.SpawnTerrain(pos.x + distanceOffset, pos.y, width, height);

        terrain.ConfigureCollider(width, height);
    }