title: displaying different texts on different button clicks in unity
body: <p>I am making a user interactive selection system using unity where, there are buttons denoting various products and the product name is to be displayed in a systematic order one below the other when the user clicks on the product. I have used OnGUI() function for  the display of product name. But on my output, all the names are getting printed super imposed over one another.</p>
  
  <p>I tied increment the y positions of the GUI.label using static variable i (defined to 0 initially). I tried increment the value of i on every click and add it to the  y position of  the GUI.label. Now when i click the second button both the first button label and second button label move to the new co ordinates.</p>
  
  <pre><code>using UnityEngine;
  using UnityEngine.EventSystems;// 1
  using UnityEngine.UI;
  
  ``public class Example : MonoBehaviour, IPointerClickHandler // 2
  
  // ... And many more available!
  {
      SpriteRenderer sprite;
      Color target = Color.red;
      int a=200,b=100;
  
      public GUIText textObject;
      public bool showGUI;
      public int s=0;
  
  
  
      public static int i=0;
  
  
  
      void Awake()
      {
          sprite = GetComponent&lt;SpriteRenderer&gt;();
      }
  
      void test()
      {
          i = i + 20;
  
          OnGUI();
      }
  
      void Update()
      {
          if (sprite)
              sprite.color = Vector4.MoveTowards(sprite.color, target, Time.deltaTime * 10);
      }
  
      public void OnPointerClick(PointerEventData eventData) // 3
      {
          showGUI = true;
          Debug.Log(gameObject.name);
          target = Color.blue;
          PlayerPrefs.SetString ("Display", gameObject.name);
          s = 1;
          test ();
  
  
      }
  
      void OnGUI()
      {
  
          if (s == 1) {
  
              GUI.color = Color.red;
              GUIStyle myStyle = new GUIStyle (GUI.skin.GetStyle ("label"));
              myStyle.fontSize = 20;
  
              GUI.Label (new Rect (a, b, 100f, 10f), "");
  
              if (showGUI) {
  
                  //GUI.Box (new Rect (a,b+i, 300f, 100f), "");
                  GUI.Label (new Rect (a, b + i, 300f, 100f), gameObject.name, myStyle);
  
                  s = 0;
              }
  
  
          }
  
  
      }
  
  
  
  }
  </code></pre>