void Start() { PrefabPoolingSystem.Prespawn(_orcPrefab, 11); PrefabPoolingSystem.Prespawn(_trollPrefab, 8); PrefabPoolingSystem.Prespawn(_ogrePrefab, 5); PrefabPoolingSystem.Prespawn(_dragonPrefab, 1); }
public void BackToHome() { Time.timeScale = 1; GameScore.LvlCompleted = false; PrefabPoolingSystem.Reset(); StartCoroutine(LoadAsynchronously(0)); }
public static PoolablePrefabData Spawn(this PrefabData prefabData, Vector2 position, Quaternion rotation) { return(PrefabPoolingSystem.Spawn( prefabData.prefab, position, rotation)); }
public static List <PoolablePrefabData> Install(this PrefabData prefabData) { return(PrefabPoolingSystem.Prespawn( prefabData.prefab, prefabData.count, prefabData.parent)); }
//// Public API public ProjectileSystem(Transform parent) { GameObject projectilePrefab = Resources.Load("Prefabs/Projectile") as GameObject; this._gameManager = GameManager.Instance; this._pool = new PrefabPoolingSystem(projectilePrefab, _gameManager.ProjectilePoolSize, parent); }
void SpawnObject(GameObject prefab, List <GameObject> list) { GameObject obj = PrefabPoolingSystem.Spawn(prefab, 5.0f * Random.insideUnitSphere, Quaternion.identity); list.Add(obj); }
void Awake() { _prefabs = _gameSkin.enemyPrefabs; _resetMinSpawnTimePeriod = _minSpawnTimePeriod; _resetMaxSpawnTimePeriod = _maxSpawnTimePeriod; PrefabPoolingSystem.Prespawn(_prefabs, _mobileSpawnPoints[0].transform.position, _mobileSpawnPoints[0].transform.rotation, 3); }
internal override void Die() { base.Die(); if (laserHitVFX) { PrefabPoolingSystem.Despawn(laserHitVFX); } }
//Needs to reset bonus in gameController //Needs to reset extra second counter in gameController private void OutOfScreenDestroy() { if (!_isFriendly) { GameController.Instance.ResetBonus(); } PrefabPoolingSystem.Despawn(this.gameObject); }
public override void Update() { CountDownAndShoot(); SetLaserPos(); if (lazer.isVisible) { raycast = Physics2D.Raycast(transform.localPosition, Vector2.down, 20f, layerMask); if (raycast) { lazer.SetPosition(1, new Vector2(lazer.transform.position.x, player.transform.position.y - 0.05f)); player.TakeDamage(currentLazerDamage); // SOUND if (!laserHitPlayer.isPlaying) { laserHitPlayer.Play(); } // VFX if (laserHitVFX == null) { laserHitVFX = PrefabPoolingSystem.Spawn(laserHitVFXPrefab, player.transform.localPosition, Quaternion.identity); } else { laserHitVFX.transform.localPosition = player.transform.localPosition; } } else { // SOUND if (laserHitPlayer.isPlaying) { laserHitPlayer.Stop(); } // VFX if (laserHitVFX != null) { PrefabPoolingSystem.Despawn(laserHitVFX); laserHitVFX = null; } } } else { if (laserHitVFX != null) { PrefabPoolingSystem.Despawn(laserHitVFX); laserHitVFX = null; } } }
private void DelayDestory() { if (_isFriendly) { GameController.Instance.TimePenalty(_timePenalty); GameController.Instance.ResetBonus(); } PrefabPoolingSystem.Despawn(this.gameObject); }
private void Awake() { _instance = this; PrefabPoolingSystem.Reset(); _resetBonusCntLimit = _bonusCntLimit; StartGame(); }
internal virtual void Die() { PrefabPoolingSystem.Spawn(deathVFXPrefab, transform.localPosition, Quaternion.identity); AudioSource.PlayClipAtPoint(deathSound, mainCamera, deathSoundVolume); GameSession.instance.AddToScore(currentScore); PrefabPoolingSystem.Despawn(gameObject); }
/* * Called by UI button Button_Replay in Canvas_GameOver * OnClick() Unity Event */ public void ReplayGame() { PrefabPoolingSystem.ClearAll(); InitFields(); UIManager.Instance.UpdateScore(GameScore.CurrentScore); _gameOverCanvas.gameObject.SetActive(false); _uiCanvas.gameObject.SetActive(true); }
//// Public API public ConstructionSystem(Transform constructionsParent) { GameObject towerPrefab = Resources.Load("Prefabs/Tower") as GameObject; GameObject wallPrefab = Resources.Load("Prefabs/Wall") as GameObject; this._gameManager = GameManager.Instance; this._towerPool = new PrefabPoolingSystem(towerPrefab, _gameManager.TowerPoolSize, constructionsParent); this._wallPool = new PrefabPoolingSystem(wallPrefab, _gameManager.WallPoolSize, constructionsParent); _mode = _gameManager.Interaction; }
void DespawnRandomObject(List <GameObject> list) { if (list.Count == 0) { return; } int i = Random.Range(0, list.Count); PrefabPoolingSystem.Despawn(list[i]); list.RemoveAt(i); }
public void ResetLength() { foreach (var segment in _ropeSegments) { PrefabPoolingSystem.Despawn(segment.gameObject); } _ropeSegments.Clear(); isDecreasing = isIncreasing = false; InitializeRope(); }
private void RemoveHealth(Health health) { if (!_healthBars.TryGetValue(health, out HealthBar healthBar)) { #if UNITY_EDITOR Debug.LogError("Health not found in HealthBars dictionary!", this); #endif return; } _healthBars.Remove(health); PrefabPoolingSystem.Despawn(healthBar.gameObject); }
private void TakeDamage(DamageDealer damageDealer, Collider2D collision) { currentHealth -= damageDealer.GetDamage(); if (currentHealth <= 0) { Die(); } else { AudioSource.PlayClipAtPoint(collision.GetComponent <Projectile>().GetImpactSound(), mainCamera, collision.GetComponent <Projectile>().GetImpactSoundVolume()); PrefabPoolingSystem.Spawn(collision.GetComponent <Projectile>().GetImpactVFX(), transform.localPosition, Quaternion.identity); } }
private IEnumerator SpawnAllEnemies(WaveConfig waveConfig) { float timeBtwnSpawns = waveConfig.GetTimeBtwnSpawns(); GameObject enemyPrefab = waveConfig.GetEnemyPrefab(); Vector3 startPos = waveConfig.GetWayPoints()[0].transform.localPosition; for (int i = 0; i < waveConfig.GetNumberOfEnemies(); i++) { GameObject enemy = PrefabPoolingSystem.Spawn(enemyPrefab, startPos, Quaternion.identity); enemy.GetComponent <EnemyPathing>().SetWaveConfig(waveConfig); enemy.GetComponent <Enemy>().IncreaseStats(statsFactor); yield return(new WaitForSeconds(timeBtwnSpawns)); } }
//Async Enemy Spawn on predefined time delay IEnumerator SpawnEnemy() { while (true) { float bombProbability = Random.Range(0f, 1f); float prevRandomPoint = 0f; int enemyPrefabIndex; int prevEnemyPrefabIndex = 0; if (bombProbability < .93f) { enemyPrefabIndex = Random.Range(0, _prefabs.Length - 1); } else { enemyPrefabIndex = _prefabs.Length - 1; } float _spawnTimePeriod = Random.Range(_minSpawnTimePeriod, _maxSpawnTimePeriod); float randomPoint = Random.Range(-2f, 2f); if (Mathf.Abs(randomPoint - prevRandomPoint) < 0.5f && ((enemyPrefabIndex == _prefabs.Length - 1) || (prevEnemyPrefabIndex == _prefabs.Length - 1))) { if (randomPoint < 0) { randomPoint += 1f; } else { randomPoint -= 1f; } } prevRandomPoint = randomPoint; prevEnemyPrefabIndex = enemyPrefabIndex; PrefabPoolingSystem.Spawn(_prefabs[enemyPrefabIndex], new Vector3(randomPoint, -6f, 0f), new Quaternion(0f, 0f, 0f, 0f)); yield return(new WaitForSeconds(_spawnTimePeriod)); } }
private void Awake() { GameObject playerProjectilesGO = new GameObject("Player Projectiles"); playerProjectilesGO.transform.SetParent(gameObject.transform); GameObject enemiesProjectilesGO = new GameObject("Enemies Projectiles"); enemiesProjectilesGO.transform.SetParent(gameObject.transform); GameObject VFXGO = new GameObject("VFX"); VFXGO.transform.SetParent(gameObject.transform); GameObject enemiesGO = new GameObject("Enemies"); enemiesGO.transform.SetParent(gameObject.transform); // Player Projectiles PrefabPoolingSystem.Prespawn(playerProjectiles[0], 6, playerProjectilesGO.transform); PrefabPoolingSystem.Prespawn(playerProjectiles[1], 12, playerProjectilesGO.transform); PrefabPoolingSystem.Prespawn(playerProjectiles[2], 4, playerProjectilesGO.transform); // Enemies Projectiles PrefabPoolingSystem.Prespawn(enemiesProjectiles[0], 20, enemiesProjectilesGO.transform); PrefabPoolingSystem.Prespawn(enemiesProjectiles[1], 20, enemiesProjectilesGO.transform); PrefabPoolingSystem.Prespawn(enemiesProjectiles[2], 20, enemiesProjectilesGO.transform); // VFX PrefabPoolingSystem.Prespawn(VFX[0], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[1], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[2], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[3], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[4], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[5], 10, VFXGO.transform); PrefabPoolingSystem.Prespawn(VFX[6], 10, VFXGO.transform); // Enemies PrefabPoolingSystem.Prespawn(enemies[0], 10, enemiesGO.transform); PrefabPoolingSystem.Prespawn(enemies[1], 10, enemiesGO.transform); PrefabPoolingSystem.Prespawn(enemies[2], 6, enemiesGO.transform); PrefabPoolingSystem.Prespawn(enemies[3], 6, enemiesGO.transform); }
IEnumerator LoadGameInBackground(int previousSceneIndex) { // Reset Static Vars PrefabPoolingSystem.Reset(); gameSession.ResetGame(); //------------------------- AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(1, LoadSceneMode.Additive); asyncLoad.allowSceneActivation = false; // Wait until the scene fully loads // (Stops at 0.9 due to allowSceneActivation = false) while (asyncLoad.progress < 0.9f) { yield return(null); } // Wait for Input // (the player press "Play") while (!startGame) { yield return(null); } // Wait a Frame until the Scene is Active yield return(asyncLoad.allowSceneActivation = true); // Optional //SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1)); // Wait a Frame until the previous Scene is Unloaded Scene previousScene = SceneManager.GetSceneByBuildIndex(previousSceneIndex); if (previousScene.isLoaded) { yield return(SceneManager.UnloadSceneAsync(previousSceneIndex)); } musicPlayer.PlayGame(); startGame = false; }
private void OnTapDestroy() { if (!System.Object.ReferenceEquals(_animator, null)) { _animator.Play("Destroy"); Invoke("DelayDestory", _animator.runtimeAnimatorController.animationClips[1].length); } else { if (_isFriendly) { GameController.Instance.TimePenalty(5f); GameController.Instance.ResetBonus(); } PrefabPoolingSystem.Despawn(this.gameObject); } GameController.Instance.UpdateScore(_enemyScoreValue); }
private void Move() { if (waypointIndex < finalIndex) { movementThisFrame = moveSpeed * Time.deltaTime; transform.localPosition = Vector2.MoveTowards(transform.localPosition, targetPos, movementThisFrame); if (transform.localPosition == targetPos) { waypointIndex++; if (waypointIndex < finalIndex) { targetPos = waypoints[waypointIndex].transform.localPosition; } } } else { PrefabPoolingSystem.Despawn(gameObject); } }
public void LoadLevel(int sceneIndex) { Time.timeScale = 1; PrefabPoolingSystem.Reset(); StartCoroutine(LoadAsynchronously(sceneIndex)); }
// Start is called before the first frame update void Start() { PrefabPoolingSystem.Prespawn(_orcPrefab, _numToSpawn); }
private void FireLvl1() { PrefabPoolingSystem.Spawn(projectile1Prefab, transform.localPosition + new Vector3(-0.5f, 0.3f, 0f), Quaternion.identity); PrefabPoolingSystem.Spawn(projectile1Prefab, transform.localPosition + new Vector3(0.5f, 0.3f, 0f), Quaternion.identity); }
private void FireLvl2() { PrefabPoolingSystem.Spawn(projectile2Prefab, transform.localPosition + new Vector3(0f, 0.7f, 0f), Quaternion.identity); }
private void OnTriggerEnter2D() { PrefabPoolingSystem.Despawn(gameObject); }