本文整理汇总了C#中Unit.GetHealth方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.GetHealth方法的具体用法?C# Unit.GetHealth怎么用?C# Unit.GetHealth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Unit
的用法示例。
在下文中一共展示了Unit.GetHealth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetHealthText
public void SetHealthText(Unit unit)
{
health_text.text = "Health: " + unit.GetHealth();
health_bar.value = unit.GetHealth() / unit.GetMaxHealth();
}
示例2: ShowEstimatedDamagePanel
public void ShowEstimatedDamagePanel(Unit target)
{
battle_prediction_panel.SetActive(true);
// Set enemy HP, out of their max HP
enemy_hp_slider.value = target.GetHealth() / target.GetMaxHealth();
// Estimate the amount of damage the selected unit will do to the target
float damage = target.CalculateDamage(selected_unit, selected_unit.location);
estimated_damage_slider.value = damage / target.GetMaxHealth();
estimated_damage_text.text = "Estimated damage: " + (int)damage;
}
示例3: CalculateDamage
// Returns how much damage the attacker would do to this unit
public float CalculateDamage(Unit attacker, Hex from)
{
// Have the damage be the percentage of the health remaining of this unit. Weak units don't do as much damage
float raw_normal_damage = attacker.GetDamage() * (attacker.GetHealth() / attacker.GetMaxHealth());
float raw_piercing_damage = attacker.GetPiercingDamage() * (attacker.GetHealth() / attacker.GetMaxHealth());
// Get the right type of defence to use. Ranged defence from ranged units
float defence = 0;
if (attacker.is_ranged_unit)
{
defence = this.GetRangedDefence();
}
else
defence = this.GetDefence();
// Modify the damage by the defence percentage. 10% defence means 90% of the damage is inflicted.
float modified_normal_damage = raw_normal_damage - (raw_normal_damage * defence);
// Piercing damage is not affected by the enemy's defense.
float damage = modified_normal_damage + raw_piercing_damage;
// Apply bonuses to damage that's been modified by the enemies' defence
// Apply bonus against specific type of unit
if (this.unit_type == Unit_Types.Melee)
damage += damage * attacker.GetMeleeBonus();
else if (this.unit_type == Unit_Types.Cavalry)
damage += damage * attacker.GetMeleeBonus();
else if (this.unit_type == Unit_Types.Ranged)
damage += damage * attacker.GetMeleeBonus();
// If the attacker is flanking, apply a flanking bonus
if (!IsFacing(from))
{
damage += damage * attacker.GetFlankingBonus();
}
return damage;
}