- Home /
Adding little delays between doing things to objects in array
Okay what I want is I have 3 objects in an array, they are all grey.
When I press on a button I want them to color white 1 by 1, with a slight delay in between, they are all stored in an array how can I do this?
Answer by smoggach · Oct 06, 2014 at 01:48 PM
I'd recommend using a Coroutine or Invoke. Coroutine lets you wait for a period of time while the function is running. Invoke lets you wait a period of time before calling a function.
http://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html
http://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
If you use UnityScript, you can just add a yield WaitForSeconds(1.0f); to your iteration loop. If you are using C#, then do as smoggach said and use a Coroutine.
I feel so limited with these, I don't really like them at all but I guess I'm stuck to them.
After using them for a while you will feel their power. They will help you to build something that feels much less limiting.
Answer by swinny89 · Oct 06, 2014 at 02:05 PM
public IEnumerator IterateWithPause()
{
SpriteRenderer[] sprites; // imagine its already pre-populated;
foreach(SpriteRenderer s in sprites)
{
s.color = Color.white;
yield return new WaitForSeconds(0.3f);
}
}
Your answer
Follow this Question
Related Questions
Storing object colors in an array. 1 Answer
implementing shuffle script 0 Answers
How To Find the Closest Object 0 Answers
GUIStyle in an inspector array 0 Answers
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers