/* * Applies texture to ub depending on its Health and Level * */ public void ApplyMainTexture() { var hp = health.GetCurrentHealthPercentage(); var text = skin.material.mainTexture; // to avoid null values if (hp > (float)HPThreshold.Medium) { text = textures[3 * (currentLevel - 1) + (int)UBTextureHPIndex.Full]; } else if ((hp > (float)HPThreshold.Low) && (hp < (float)HPThreshold.Medium)) { text = textures[3 * (currentLevel - 1) + (int)UBTextureHPIndex.Medium]; } else { text = textures[3 * (currentLevel - 1) + (int)UBTextureHPIndex.Low]; } skin.material.mainTexture = text; }
// Receive damage by weapon public void ReceiveDamage(float damage) { try { health.LoseHealth(damage); NotifyHUD(); //change texture if hp is bellow 50% if (health.GetCurrentHealthPercentage() < damageThreshold) { skin.material.mainTexture = damagedTexture; } } catch (Exception) { NotifyHUD(); Die(); } }