How to repeat a series of transitions

Help, support and information for our Beautiful Transitions Unity Asset
Post Reply
mahewitt
Site Admin
Posts: 274
Joined: Thu May 05, 2016 8:06 pm

How to repeat a series of transitions

Post by mahewitt » Fri Jun 17, 2016 6:38 am

Is there an easy way to repeat a series of transitions a certain number of times (in code)?

I'm trying to create a blink effect and I want the game object to blink sometimes for 3 seconds and sometimes for 5 seconds and sometimes for 7 seconds.
It the moment, the best way to achieve this is probably through the use of a coroutine. Something like:

Code: Select all

    ....
    StartCoroutine(Blink( this.gameObject, 5, 2))
    ....

IEnumerator Blink(GameObject gameObject, int count, float delay)
{
    for (var i = 0; i < count; i++) {
        new Scale(gameObject, Vector3.one, Vector3.zero, duration: 0.5f).Scale(Vector3.zero, Vector3.one, duration: 0.5f).GetChainRoot().Start();
        yield return new WaitForSeconds(delay);
    }
}
I will look into getting a repeat method added to a future version to simplify the above, but will need a bit of thinking as to how best to handle chained calls etc..

Post Reply