// Use this for initialization void Start() { m_currentHealth = m_StartHealth; m_state = EWhaleState.INTRO; m_stateTime = 0; m_effectTime = 0; UpdateState(); }
public void Heal() { if (m_currentHealth < m_MaxHealth) { m_currentHealth++; if (m_currentHealth == m_MaxHealth) { m_state = EWhaleState.OUTRO; m_stateTime = 0; SoundManager.Get().PlayOneShotSound(m_WhaleHappySound, m_WhaleVolume, transform.position); } } }
public void Damage() { if (m_currentHealth > 0) { m_currentHealth--; if (m_currentHealth == 0) { m_state = EWhaleState.DEATH; m_stateTime = 0; SoundManager.Get().PlayOneShotSound(m_WhaleDeadSound, m_WhaleVolume, transform.position); } else { SetEffect(EEffectType.DAMAGE); } } }
void UpdateState() { switch (m_state) { case EWhaleState.INTRO: if (m_stateTime < m_IntroTime) { UpdateIntroAnimState(m_stateTime / m_IntroTime); } else { m_state = EWhaleState.IDLE; m_stateTime = 0.0f; transform.position = m_SpawnLocation; } break; case EWhaleState.OUTRO: if (m_stateTime < m_OutroTime) { UpdateOutroAnimState(m_stateTime / m_OutroTime); } else { WhaleManager manager = GetComponentInParent <WhaleManager>(); manager.WhaleFullyFed(this.gameObject); } break; case EWhaleState.DEATH: if (m_stateTime < m_DeathTime) { UpdateDeathAnimState(m_stateTime / m_DeathTime); } else { WhaleManager manager = GetComponentInParent <WhaleManager>(); manager.WhaleKilled(this.gameObject); } break; } if (m_effectTime > 0.0f) { Color clr = GetComponent <Renderer>().material.color; Color newClr; if (m_effectType == EEffectType.DAMAGE) { newClr = new Color(2.0f, 0.3f, 0.3f, clr.a); } else if (m_effectType == EEffectType.EAT) { newClr = new Color(0.2f, 1.0f, 0.0f, clr.a); } else { newClr = new Color(1.0f, 1.0f, 1.0f, clr.a); } m_effectTime -= Time.deltaTime; GetComponent <Renderer>().material.color = Color.Lerp(new Color(1.0f, 1.0f, 1.0f, clr.a), newClr, Mathf.Max(m_effectTime / m_EffectTimeMax, 0.0f)); } }