- Home /
Question by
Decycle · Jul 15, 2018 at 03:24 AM ·
c#coroutines
Check if a method hasn't been used for one second
I want to create a health bar that when the creature hasn't be hit for a second, its health bar will disappear. How can I do that? Please use C# because I don't really understand javascript.
Comment
Best Answer
Answer by Grundadrakk · Jul 15, 2018 at 05:20 AM
bool _isEnabled; float _timerDisappear;
private void Update()
{
if (_isEnabled)
{
_timerDisappear += Time.deltaTime;
if (_timerDisappear > 1.0f)
{
_healtBar.SetActive(false);
_isEnabled = false;
}
}
}
private void WasHit()
{
_healthBar.SetActive(true);
_isEnabled = true;
_timerDisappear = 0.0f;
}