I am having some issues getting my head around the Coroutine concept in C#
Question
I have a list of objects that I want to manipulate via a script but I want that action to be preformed a frame latter for each consecutive object so as to reduce the load on the CPU.
My sudo code is as follows:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void MainAction(GameObject[] TargetList){
int Loop = 0;
foreach (GameObject Target in TargetList){
StartCoroutine(Action(Loop,Target));
Loop++;
}
}
IEnumerator Action(int Loop,GameObject Target){
yield return new WaitForSeconds(Loop/2f);
Target.transform.localScale = new Vector3(0,0,0);
}
void Update(){
GameObject[] TargetList = GameObject.FindGameObjectsWithTag("Target");
MainAction(TargetList);
}
}
Any help would be really appreciated!