Health
The Health component goes on the root transform of a vehicle, and manages collectively all the damageables on the vehicle.
Toggle Vehicle Damage
To toggle vehicle damage in the editor, you can check/uncheck the Is Damageable checkbox in the inspector of the Health component.
To toggle it during gameplay, use the following code:
// Make vehicle un-damageable
myVehicleHealth.IsDamageable = false;
// Make vehicle damageable
myVehicleHealth.IsDamageable = true;
Toggle Vehicle Healing
To toggle vehicle healing in the editor, you can check/uncheck the Is Healable checkbox in the inspector of the Health component.
To toggle it during gameplay, use the following code:
// Make vehicle un-healable
myVehicleHealth.IsHealable = false;
// Make vehicle healable
myVehicleHealth.IsHealable = true;
Destroy Damageables
To destroy all the damageables on a vehicle during gameplay, use the following code:
// Destroy all damageables on the vehicle
myVehicleHealth.DestroyAllDamageables();
Restore Damageables
To restore all the damageables on the vehicle, use the following code:
// Restore all damageables on vehicle
myVehicleHealth.ResetHealth();
Vehicle Health Info
To query vehicle health information, you can use the following code:
// Get current health by health type
float currentHealth = myVehicleHealth.GetCurrentHealthByType(someHealthType);
// Get max health by health type
float maxHealth = myVehicleHealth.GetMaxHealthByType(someHealthType);
// Get current health fraction (0.0 to 1.0) by health type (useful for health bars)
float healthFraction = myVehicleHealth.GetCurrentHealthFractionByType(someHealthType);
Last updated
Was this helpful?