Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Coroutine with multiple Loops

$
0
0
Hi, I've checked the documentation, tutorials and read relating Q/A but it seems I can't find a solution. I use a coroutine to place a number in the center of the screen and then move a letter from the center to the one of the four corners of the screen. The code iterates only once (blink of nr 1 and moves the first letter). But I can't get the print "reached the target" on the console. It seems stuck in the while loop. Can anybody help me? Cheers Nikola public IEnumerator PlaceLetter() { foreach (GameObject nrTemp in numbers) { // Blink for 1sec in the center of the screen GameObject number = Instantiate (nrTemp) as GameObject; number.SetActive (true); yield return new WaitForSeconds (1); number.SetActive (false); Destroy (number); yield return new WaitForSeconds (1); foreach (GameObject goTemp in letters) { // place letter in a corner of the screen GameObject letter = Instantiate (goTemp) as GameObject; letter.SetActive (true); Vector3 currentPosition = letter.transform.position; foreach (Vector3 tpTemp in targetPositions) { while (Vector3.Distance (currentPosition, tpTemp) > 0.1f) { letter.transform.position = Vector3.Lerp (letter.transform.position, tpTemp, speed * Time.deltaTime); yield return null; } print ("reached the target"); } } } }

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>