mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 03:53:04 +00:00
healthbar above peds is only shown for some time interval after ped is damaged
This commit is contained in:
parent
dc589146dc
commit
5bc12124ac
2 changed files with 7 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue