void OnNetworkVarSync(INetworkVar _cVarInstance) { // If the updated network var was the health state if (_cVarInstance == m_HealthState) { // Switch on the current health state switch (CurrentHealthState) { // Alive case HealthState.ALIVE: { // Enable input transform.GetComponent <CPlayerGroundMotor>().ReenableInput(this); transform.GetComponent <CPlayerHead>().ReenableInput(this); // Break switch break; } // Dead case HealthState.DEAD: { // Break switch break; } // Downed case HealthState.DOWNED: { // Disable input transform.GetComponent <CPlayerGroundMotor>().DisableInput(this); transform.GetComponent <CPlayerHead>().DisableInput(this); // Break switch break; } // Default default: { // Log the current health state as an error Debug.LogError("Health state: " + CurrentHealthState.ToString()); // Break switch break; } } } }
private void UpdateHealthState(GameObject _TargetPlayer, float _fHealthCurrentValue, float _fHealthPreviousValue) { // Set an invalid initial previous health state HealthState PrevHealthState = HealthState.INVALID; // Switch on the current health state switch (CurrentHealthState) { // Alive case HealthState.ALIVE: { // If the player's health is the minimum health if (m_fHealth.Get() == k_fMinHealth) { // Change player's state to downed PrevHealthState = CurrentHealthState; CurrentHealthState = HealthState.DOWNED; } // Break switch break; } // Dead case HealthState.DEAD: { // If the player's health is not the minimum health if (!(m_fHealth.Get() == k_fMinHealth)) { // Change player's state to downed PrevHealthState = CurrentHealthState; CurrentHealthState = HealthState.ALIVE; } // Break switch break; } // Downed case HealthState.DOWNED: { // Increment the downed timer fTimerDowned += Time.deltaTime; // If downed timer is equal to or greater than the max downed timer duration if (fTimerDowned >= k_fTimerDownedMaxDuration) { // Change player's state to dead PrevHealthState = CurrentHealthState; CurrentHealthState = HealthState.DEAD; // Reset downed timer fTimerDowned = 0.0f; } // Break switch break; } // Default default: { // Log the current health state as an error Debug.LogError("Health state: " + CurrentHealthState.ToString()); // Break switch break; } } // If the previous health state is valid // And previous health state is not the same as the current health state if ((PrevHealthState != HealthState.INVALID) && (PrevHealthState != HealthState.MAX) && (PrevHealthState != CurrentHealthState)) { // Trigger EventHealthStateChanged EventHealthStateChanged(gameObject, CurrentHealthState, PrevHealthState); } }