// Calculate the player's rounded health and display it on the UI. public void SetHealth() { List <VehicleHealthManager> vehicles = new List <VehicleHealthManager>(FindObjectsOfType <VehicleHealthManager>()); PlayerEntry entry = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); int teamId = entry.teamId; entry.Release(); foreach (VehicleHealthManager vehicle in vehicles) { if (vehicle.teamId == teamId) { if (Mathf.CeilToInt(vehicle.health) != previousRoundedHealth) { damageTaken = Mathf.CeilToInt(vehicle.health) - previousRoundedHealth; Instantiate(damageIndicator, damageIndicatorInstantiateTransform); if (vehicle.health < 0f) { vehicle.health = 0f; } healthLabel.text = Mathf.CeilToInt(vehicle.health).ToString(); previousRoundedHealth = Mathf.CeilToInt(vehicle.health); healthBar.SetProgressBar(vehicle.scaledHealth); healthBar.SetNumber(Mathf.CeilToInt(vehicle.health).ToString()); } break; } } }
// Start is called before the first frame update public void UpdateDriverBar(float currentValue, float maxValue) { driverBar.SetProgressBar(currentValue / maxValue); driverBar.SetNumber(Mathf.RoundToInt((currentValue / maxValue) * 100).ToString()); if (currentValue >= maxValue && isDriver) { fullDriverBarObject.SetActive(true); } else if (isDriver) { fullDriverBarObject.SetActive(false); } }