healthbar above peds is only shown for some time interval after ped is damaged

This commit is contained in:
in0finite 2021-10-19 23:45:07 +02:00
parent dc589146dc
commit 5bc12124ac
2 changed files with 7 additions and 1 deletions

View file

@ -29,6 +29,9 @@ namespace SanAndreasUnity.Behaviours
/// </summary>
public DamageInfo KillingDamageInfo { get; set; }
public float LastTimeWhenDamaged { get; private set; }
public float TimeSinceDamaged => Time.time - this.LastTimeWhenDamaged;
private bool m_alreadyKilled = false;
public class DamageResult
@ -79,7 +82,7 @@ namespace SanAndreasUnity.Behaviours
void UpdateHealthBar ()
{
bool shouldBeVisible = PedManager.Instance.displayHealthBarAbovePeds && !this.IsControlledByLocalPlayer;
bool shouldBeVisible = this.TimeSinceDamaged < PedManager.Instance.healthBarVisibleTimeAfterDamage && !this.IsControlledByLocalPlayer;
this.HealthBar.gameObject.SetActive (shouldBeVisible);
if (shouldBeVisible)
@ -127,6 +130,8 @@ namespace SanAndreasUnity.Behaviours
if (this.Health <= 0)
return;
this.LastTimeWhenDamaged = Time.time;
var damageInfo = this.Damageable.LastDamageInfo;
var damageResult = this.CurrentState.OnDamaged(damageInfo);

View file

@ -43,6 +43,7 @@ namespace SanAndreasUnity.Behaviours
[Header("Health bar")]
public bool displayHealthBarAbovePeds = false;
public float healthBarVisibleTimeAfterDamage = 3f;
public float healthBarWorldWidth = 0.5f;
public float healthBarWorldHeight = 0.1f;
public float healthBarMaxScreenHeight = 20f;