IEnumerator MonsterDeath() { TapInterface.ClearMonster(); yield return(new WaitForSeconds(GameManager.DEATH_DELAY)); // Event here? if (Random.Range(0f, 1f) < DataManager.Instance.globalData.GetGlobalAsFloat(GlobalProps.TAP_BATTLE_EVENT_TRIGGER) && !data.EventTriggered) { //if (Random.Range(0f, 1f) < 2f) { // Test if so we can ignore the logic // See if we have seen this event before? storyEventTimer = DataManager.Instance.globalData.GetGlobalAsFloat(GlobalProps.TAP_BATTLE_EVENT_DURATION); RemoveMonster(); // Enable the event indicator here and as a click action call the story EventOfInterest.SetActive(true); } while (storyEvent || storyEventTimer > 0f) { storyEventTimer -= Time.deltaTime; yield return(new WaitForEndOfFrame()); } EventOfInterest.SetActive(false); storyEventTimer = 0f; // Check if that was the last monster if (wasLastMonster()) { Phase = BattlePhases.Results; ShowResults(); } else { NewMonster(); } }
private void Update() { switch (_currentPhase) { case BattlePhases.Entering: if (transform.position.y <= onscreenY) { if (mgr.NumKills > 0) { src.PlayOneShot(midClip); _currentPhase = BattlePhases.OnScreen; _currentHP = maxHP; col.enabled = true; } else { _currentPhase = BattlePhases.HiddenVictory; rb.velocity = Vector2.zero; StartCoroutine(DoHiddenVictory()); } } else { rb.velocity = new Vector2(0, -1 * verticalVelocity); } break; case BattlePhases.OnScreen: if (_currentHP <= 0) { src.PlayOneShot(exitClip); col.enabled = false; _currentPhase = BattlePhases.Exiting; _nextExplostionTime = Time.time + 0.1f; } else { rb.velocity = new Vector2(Mathf.Sin(Time.time / 0.5f) * 0.2f, 0); } break; case BattlePhases.Exiting: if (transform.position.y >= offscreenY) { // Fully offscreen _currentPhase = BattlePhases.Over; _nextExplostionTime = float.PositiveInfinity; rb.simulated = false; afterDefeated.Invoke(); } else { rb.velocity = new Vector2(0, 0.5f * verticalVelocity); // Explosions if (Time.time >= _nextExplostionTime) { // Find a new place to explode int newIndex = _lastExplosionIndex; while (newIndex == _lastExplosionIndex) { newIndex = Random.Range(0, explosionPositions.Length); } explosionParticles.transform.position = explosionPositions[newIndex].position; explosionParticles.Play(); _lastExplosionIndex = newIndex; src.PlayOneShot(explosionClip); _nextExplostionTime += explosionInterval; } } break; } }
public void StartMidbossPhase() { rb.simulated = true; _currentPhase = BattlePhases.Entering; src.PlayOneShot(introClip); }