I have a list that is filled randomly with vector3s and a time to go with them. I want to be able to run each element in order but only if the previous has been run. I am curious if any one has programmed something along these lines before or has a good approach.
Vector3 first = transform.up;
float time = 3.0f;
Vector3 second = transform.up;
float time2 = 5.0f;
Vector3 third = transform.up;
float time3 = 8.0f;
applyDirection(first,time);
wait and see if first is complete
if true
applyDirection(second,time2);
else
nothing
public bool canProceed = false;
public IEnumerator void WaitForTimer(float X)
{
int timer = 0;
canProceed = false;
while (timer < X)
{
yield return null;
}
canProceed= true;
Debug.Log( " Wait for X number of seconds, You can now Proceed";
}
}
Use Coroutines to create timers and do your calculation. If you want to learn something new, Learn Promise timers
void Start () {
v = new Vector3[3];
f = new float[3];
v [0] = new Vector3 (1f, 1f, 1f);
v [1] = new Vector3 (2f, 2f, 2f);
v [2] = new Vector3 (3f, 3f, 3f);
f [0] = 1f;
f [1] = 2f;
f [2] = 3f;
}
void Update(){
if(Input.GetKeyDown("space")){doit();}
}
void doit () {if (idx < v.Length) {
print ("vector is :" + v [idx] + "float is: " + f [idx]);
idx++;
}
else {print ("im all done doing it");}
}