GUI label - for loop - racing off screen problem


I’m trying to output my string array with a length of four through a ‘for’ loop, itterating them, but when my GUI is created, it falls down the page almost instantly, in the small gap I can see the spacing is correct, each spaced in the Y axis by an extra 20.

But something I’m doing is making the whole collection of GUI labels race down off the screen.

using UnityEngine;
using System.Collections;

	public class referenceScript : MonoBehaviour  

	private Inventory myinventory;
	private float windowX = 50.0f;
	private float windowY = 50.0f;

	void Start(){
		myinventory = gameObject.GetComponent<Inventory>();

	void Update()

	void OnGUI() {
				for (int i = 0; i < myinventory.myItemNameArray.Length; i++) {
						GUI.Label (new Rect (windowX, windowY, 100, 20), myinventory.myItemNameArray *);*
  •  	windowY += 20f;*
  •  		}*
  •  }*
  • }*

OnGUI is called multiple times per frame. So, you are incrementing wndowY multiple times per frame.

You should calculate that else where with >>>

yield return new WaitForSeconds(waitTime)

What @Phles said… reset your windowY - Like windowY=0