// Use this for initialization void Awake() { parallax = GetComponentInParent <Parallax>(); parallax.Initialize(); CreatePool(pooledPrefabs); //Create initial roads if (pool.Count > 0) { for (int i = 1; i <= 2; i++) { if ((sky && i == 1) || !sky) { GameObject toRemove; if (!generateChunk) { toRemove = pool[Random.Range(0, pool.Count)]; } else { toRemove = pool[0]; toRemove.tag = "temp"; } if (sky) { toRemove.transform.position = spawnLocation.position + new Vector3(-25.6f, 0, 0); } else { toRemove.transform.position = spawnLocation.position + new Vector3(-11.5f * i, 0, 0); } toRemove.SetActive(true); parallax.Tiles.Add(toRemove.GetComponent <TileScroll>()); pool.Remove(toRemove); } } } if (!sky) { GetObject(); } }
private void Initialize() { _spawnTimer = 0; _spawnDelay = _config.EnemySpawnDelay; _levelUpTimer = _config.LevelUpTimer; _score = 0; _currentLevel = 0; _enemies = new List <IEnemy>(); _playMode = true; _onPlayerDied = () => _playMode = false; EventManager.OnEnemyDied += OnEnemyDied; EventManager.OnPlayerDied += _onPlayerDied; EventManager.Pause += Pause; EventManager.UnPause += UnPause; _floor.Initialize(OnEnemyLeftArea, OnBonusLeftArea); _background.Initialize(_player); _stars.Initialize(_player); _yellowStars.Initialize(_player); SetBounds(); EventManager.Pause(); }
/// <summary> /// Initialize all in-game features and begin the game. /// </summary> private void PlayGame() { // Hide Press any key to play text. pressAnyKey.SetActive(false); // Reveal the distance UI element. ToggleDistanceUIElements(true); // Start the parallax effect. parallaxManager.Initialize(); // Start the spawning of beverages. beverageManager.shouldSpawn = true; // Make the player run. mainCharacter.GetComponent <Animator>().SetBool("isRunning", true); mainCharacter.GetComponent <Player>().shouldDetectForMovementKeys = true; // Set the player's in-game position Vector3 mainCharacterPosition = mainCharacter.transform.position; Vector3 mainCharacterInGamePosition = new Vector3(-7.0f, mainCharacterPosition.y, mainCharacterPosition.z); // Smoothly move the player to his in-game position float speed = (parallaxManager.scrollSpeed - 1) * Time.deltaTime; SmoothlyMoveObjectTo(mainCharacter, mainCharacterInGamePosition, -speed); // Smoothly move the policemen to their in-game positions. GameObject[] policemen = GameObject.FindGameObjectsWithTag("Policeman"); foreach (GameObject policeman in policemen) { Vector3 policemanPosition = policeman.transform.position; Vector3 policemanInGamePosition = new Vector3(Mathf.Floor(policemanPosition.x) - 8.0f, policemanPosition.y, policemanPosition.z); SmoothlyMoveObjectTo(policeman, policemanInGamePosition, -speed); } }