How to run an event at a perticular time interval.
Let me explain my question.
I have a character which should get blinked for a perticular time while attacked.
So for that i have to ger the renderer of the character on an off one after.
THE REST OF MY CODE IS READY.
So, please can anyone help me by showing c# script how to on and off the renderer one by one in a perticular time.
Thankz in advance…!!!
I’d do this using a Coroutine to perform an action every N seconds.
Something like this:
private bool _blink = false;
private void Start()
{
_blink = true;
StartCoroutine(Blink());
}
private IEnumerator Blink()
{
while( _blink == true )
{
MyBlinkEvent();
yield return new WaitForSeconds(1.0f); // change the value to fit your needs.
}
}
In that case I start a Coroutine called Blink. It will loop as long as _blink value is true. It will call MyBlinkEvent() then wait for 1.0f before calling it again.
I hope it helps.