- Home /
IEnumerator stops at yield
Dear All,
I have a problem with IEnumerator which takes a screenshot, waits for 5 seconds and then loops back and takes other screenshots. I have a working solution as long as I am calling this IEnumerator from a specific function it works like a charm:
public void OnMouseDown()
{
StartCoroutine(TakeScreenshot());
}
But if I put this StartCoroutine to other places like void Start() or call it from other script, the IEnumerator starts, but stops at the yield return new WaitForSeconds(5); line. Why is it happening?
As always any help and hints are welcome and thanked in advance.
Answer by srancsik · Nov 04, 2013 at 08:57 AM
Sorry here it is, marked with a "*" section you can see, where IEnumerator gets stuck.
public IEnumerator TakeScreenshot()
{
//SCREENSHOT TAKING STARTS
string ScreenShotString;
MCamera.SetActive(false);
SCamera.SetActive(true);
Camera x = MCamera.GetComponent("Camera") as Camera;
x.enabled=false;
Camera y = SCamera.GetComponent("Camera") as Camera;
y.enabled=true;
//y.aspect=297f/210f; //SET ASPECT RATIO TO A4 SIZE
for (int ig = 0; ig<13; ig++){
(GameObject.Find("Rmenu").GetComponent("Page") as Page).PageNumber=ig;
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("0")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("1")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("2")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("3")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("4")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("5")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("6")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("7")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("8")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("9")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("10")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("11")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject gono in GameObject.FindGameObjectsWithTag("12")){if(gono.transform.position.z>=1000){}else{gono.transform.position+=new Vector3(0,0,1000);}}
foreach(GameObject go in GameObject.FindGameObjectsWithTag(ig.ToString()))
{
if(go.transform.position.z<0.000000001){
}
else
{
go.transform.position-=new Vector3(0,0,1000);
Debug.LogWarning("EGYEZÉS ÁG");
}
}
ScreenShotString=Application.dataPath+"/SS"+ig.ToString()+".mon";
Debug.LogWarning(ScreenShotString);
Application.CaptureScreenshot(ScreenShotString,4);
Debug.LogWarning("Still Working");
yield return new WaitForSeconds(5);
//***************************************************************
//THIS IS WHERE THE "FOR" CYCLE STOPS, NOTHING HAPPENS AFTERWARDS
//***************************************************************
Debug.LogWarning("WaitForSeconds did not stop me");
}
//End of screenshot taking
//Reset cameras
MCamera.SetActive(true);
SCamera.SetActive(false);
x.enabled=true;
y.enabled=false;
OrderDetails z = (OrderDetails)(GameObject.Find ("Mcamera").GetComponent("OrderDetails"));
string a = System.DateTime.Now.ToString("yyyyMMdd_hhmmss");
FileNameString=a+"_"+z.OrderingPerson;
Debug.LogWarning(FileNameString.ToString());
//Upload to FTP
FTPUploadStart();
}
Please don't post comments as answers, ins$$anonymous$$d use the Add new comment button to reply to someone else's comment.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121152im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
yield return M() vs yield return StartCoroutine 2 Answers
2D Grid Movement - StartCoroutine, IEnumerator, SmoothMovement best practices? 0 Answers
How to wait for Coroutine to finish? 2 Answers
Why is my StartCoroutine within a IEnumerator bombing Unity? C# 1 Answer
How to appear object on trigger delay? 2 Answers