Ejemplo n.º 1
0
    private void HandleObstacleSpawning()
    {
        GameManager.Instance.secondsToNextObstacles -= Time.deltaTime;
        if (GameManager.Instance.secondsToNextObstacles <= 0)
        {
            var indecies = Enumerable.Range(0, allLanes.Length).OrderBy(x => Random.value).Take(Random.Range(1, allLanes.Length - 1)).ToList();
            for (int i = 0; i < indecies.Count; i++)
            {
                var lineDepth = allLanes[indecies[i]].transform.position.z;

                var nextObstacle = _objectSpawner.NextObjectToSpawn();

                Instantiate(
                    nextObstacle.gameObject,
                    new Vector3(Config.rightLineLimit, 0, lineDepth),
                    nextObstacle.transform.rotation,
                    _obstacleContainer
                    );
            }

            GameManager.Instance.secondsToNextObstacles = Random.Range(0.5f, 1f) * Config.levelRunSpeed;
        }
    }