Exemplo n.º 1
0
    IEnumerator SpawnObstacle()
    {
        spawning = true;
        yield return(new WaitForSeconds(spawnCD));

        for (int i = 0; i < spawnCount; i++)
        {
            int listEntry = Random.Range(0, spawnPoints.Count);

            if (listEntry == lastSpawnPointIdx)
            {
                continue;
            }

            lastSpawnPointIdx = listEntry;

            GameObject spawnObject;

            if (Random.value < GameManager.Instance.coinSpawnRate)
            {
                spawnObject = coinList[Random.Range(0, coinList.Count)];
            }
            else
            {
                spawnObject = obstacleList[Random.Range(0, obstacleList.Count)];
            }

            GameObject objInstance;

            if (spawnObject.tag.Contains("Coin"))
            {
                objInstance = Instantiate(spawnObject, spawnPoints[listEntry] + new Vector3(xSpawnOffset, 0.5f, 0), Quaternion.identity);
                //objInstance.GetComponent<Rigidbody2D>().velocity = new Vector3(GameManager.Instance.GetRoadSpeed() * 0.75f, 0, 0);
            }
            else
            {
                objInstance = Instantiate(spawnObject, spawnPoints[listEntry] + new Vector3(xSpawnOffset, 0.5f, 0), Quaternion.identity);
            }

            if (objInstance.GetComponent <SpriteRenderer>().isVisible)
            {
                objInstance.transform.position = new Vector3(objInstance.transform.position.x + 10, objInstance.transform.position.y, 0);
            }

            if (!movingObstacle)
            {
                objInstance.transform.parent = tileMap.transform;
            }
            else
            {
                ObstacleMove moveScript = spawnObject.GetComponent <ObstacleMove>();
                if (moveScript != null)
                {
                    moveScript.speed = obstacleSpeed;
                }
            }
        }

        spawning = false;
    }
Exemplo n.º 2
0
    private void SpawnObstacle()
    {
        var          randomIndex = Random.Range(0, _obstacles.Count);
        ObstacleMove newObstacle = Instantiate(_obstacles[randomIndex], _spawnerPoint);

        newObstacle.SetSpeed(_obstaclesSpeed);
    }
Exemplo n.º 3
0
    // Spawns an object and returns its depth.
    private float SpawnObstacle(int ind)
    {
        GameObject which    = typeObstacles[ind];
        GameObject instance = (GameObject)Instantiate(
            which, spawnPoint + transform.position, transform.rotation);
        float depth = instance.GetComponent <ObstacleMove>().depth;

        // With probability 0.5, flip.
        if (Random.value < 0.5f &&
            ind != (int)ObstacleId.Loop && ind != (int)ObstacleId.ReverseLoop)
        {
            instance.transform.Rotate(new Vector3(0.0f, 0.0f, 1.0f), 180.0f);
            instance.transform.Rotate(new Vector3(0.0f, 1.0f, 0.0f), 180.0f);
            // When rotating along Y axis, we must change direction.
            ObstacleMove om = instance.GetComponent <ObstacleMove>();
            om.direction *= -1;
            instance.transform.Translate(0.0f, 0.0f, om.direction * om.depth);
        }
        return(depth);
    }