Can I use the IEnumerator in my example? (If yes, how?)
I am loading in transformed camera data (a 2D array, every cell in this array[x,y] corresponds to a certain pixel[x,y]). When the intensity of a certain cell/pixel is above a certain value, my script saves the x and y coordinates of this cell/pixel. This all works fine.
However, sometimes the intensity is not above the treshold and as a result, there are no coordinates saved. I was wondering whether I could use my mouse to click on the right position in the screen to approximately point the position where the cell with a high intensity should be detected.
However, this is impossible, because the update loop just moves on and doesn't give me the time to click on the correct position on the screen.
I read something about the IEnumerator, that this was advised to people to use, because the update function cannot be paused. My IEnumerator function is as follows:
IEnumerator WaitForMouseClick(int n)
{
bool Click = false;
do
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (Input.GetMouseButtonDown(0))
{
Debug.log("clicked");
posX = (int)Input.mousePosition.x;
posY = (int)Input.mousePosition.y;
Continue = false;
Click = true;
yield break;
}
}
yield return null;
} while(Click == false);
}
It might be important to tell that my script needs the x and y positions, so it shouldn't move on until I clicked somewhere. Otherwise, I'll get an error. Can somebody help me?
Thanks in advance!
Your answer
Follow this Question
Related Questions
The location of the object by points 0 Answers
How to add a " Achievement unlocked " text and a collectible after completing all objectives 0 Answers
playing multiple sound on gameobject 1 Answer
How to interrupt wait coroutine in a loop? 0 Answers
Let the Camera Face the middle of the Map while still following the Player? 1 Answer