private void LiveCountHasChangedEventHandler(LiveCountHasChangedEvent liveCountHasChangedEvent)
 {
     // We do the logic only if lives count reached zero
     if (liveCountHasChangedEvent.Lives == 0)
     {
         GlobalEventSystem<GameHasEndedEvent>.EventHappened -= GameHasEndedEventHandler;
         GlobalEventSystem<GameHasEndedEvent>.Raise(new GameHasEndedEvent(true));
         Time.timeScale = 0f;
         LevelHasEndedPanel.gameObject.SetActive(true);
         LevelHasEndedPanel.DisplayLevelHasEndedPanel(true);
     }
 }
Exemple #2
0
        /// <summary>
        /// Handler is called when lives have changed
        /// We change the tower sprite here based on current live ratio
        /// </summary>
        /// <param name="liveCountHasChangedEvent">Event data</param>
        private void LivesChangedEventHandler(LiveCountHasChangedEvent liveCountHasChangedEvent)
        {
            // Getting our lives ratio, value from 0 to 1
            var ratio = LivesRatio();

            // If we're pretty healthy, set the sprite to the second one
            if (ratio < 0.75f && ratio > 0.4f)
            {
                _renderer.sprite = _sprites[1];
            }
            // If we're not that healthy, set the sprite to the third one
            else if (ratio < 0.4f && ratio > 0.1f)
            {
                _renderer.sprite = _sprites[2];
            }
            // If we're dead, set to the dead sprite
            else if (ratio < 0.1f)
            {
                _renderer.sprite = _sprites[3];
            }
        }