public void Die(BlackHole blackHole) { Rigidbody rb = GetComponent <Rigidbody>(); rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; dying = false; if (type == blackHole.EnemyType) { GameObject g = Instantiate(explosionPrefab); g.transform.position = transform.position; } OnDead?.Invoke(this, blackHole); }
void HandleOnDead(Enemy enemy, BlackHole blackHole) { // Put the enemy back in the pool MoveEnemyToPool(enemy.gameObject); // If the enemy color doesn't match the black hole colore we put the enemy back in the list if (enemy.Type != blackHole.EnemyType) { // Send the enemy back to the enemy list enemies.Add(enemy.Type); // Add penalty time timeScore += penaltyTime; OnPenaltyTime?.Invoke(penaltyTime, blackHole); } else { OnEnemyRemoved?.Invoke(enemy); } // Decrease number of enemies on screen enemiesOnScreen--; // Check if the level is completed if (enemiesOnScreen == 0 && enemies.Count == 0) { // Stop running running = false; // Game completed //GameProgressManager.Instance.SetLevelBeaten(GameManager.Instance.GetCurrentLevelId(), GameManager.Instance.GameSpeed); GameProgressManager.Instance.SetLevelBeatenAsync(GameManager.Instance.GetCurrentLevelId(), GameManager.Instance.GameSpeed).ContinueWith(task => { if (task.IsCompleted) { if (task.Result) { Debug.Log("GameProgress saved online"); invokeOnLevelBeaten = true; onProgressFailed = false; } else { Debug.LogWarning("Can't save GameProgress online"); invokeOnLevelBeaten = false; onProgressFailed = true; } } else { Debug.Log("GameProgress saving failed or interrupted"); invokeOnLevelBeaten = false; onProgressFailed = true; } }); //StartCoroutine(EndingLevel()); //OnLevelBeaten?.Invoke(); } }
void HandleOnPenalty(float time, BlackHole blackHole) { penaltyFx.transform.position = blackHole.transform.position; penaltyFx.GetComponent <ParticleSystem>().Play(); }