The endless emergence of the prefab position?

public class SpawnMilk : MonoBehaviour {

 public GameObject milk;
 GameObject[] milks;
 public GameObject bgPan;

 public int number;

 public float timeBtwMilk;

 private void Start ()
 milks = new GameObject[number];
 StartCoroutine (spawnMilk());

 IEnumerator spawnMilk ()

 <b>for (int i = 0; i < number; i++) {
 GameObject childOjbect = milks[i] = Instantiate (milk, new Vector3(1102f, -312.85 f, 0), Quaternion.identity);
 childOjbect.transform.SetParent (bgPan.transform, false);
 yield return new WaitForSeconds (timeBtwMilk);</b>

 while (true) {
 for (int i = 0; i < number; i++) {
 //GameObject childObject = milks [i];
 milks [i].transform.position = new Vector3 (1102f, -312.85 f, 0);
 //childObject.transform.SetParent (bgPan.transform, false);
 yield return new WaitForSeconds (timeBtwMilk);

Endlessly appears prefab. In my case, their only two appears, they move along the x-axis, then the first should return again to his former position and so on to infinity. But I'm doing it all in canvas. If in the first case(with spawna object) all work, then how to return to their former place - is not clear. You commented out what I tried to do, but it is not working.
June 10th 19 at 15:50
0 answer

Find more questions by tags Mobile developmentC#Android