title: instantiate a Popup when click a button in unity
body: <p>I want to show popup when press the button.</p>
  
  <p><a href="https://i.stack.imgur.com/5RRiX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5RRiX.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/H547M.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H547M.jpg" alt="enter image description here"></a></p>
  
  <p>But now it looks like this</p>
  
  <p><a href="https://i.stack.imgur.com/p2eSz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p2eSz.jpg" alt="enter image description here"></a></p>
  
  <p>I have viewed many tutorials about how to make a popup when press the button.</p>
  
  <p>But they all make the popup by script,not instantiate the prefab.</p>
  
  <p>I'm not sure if I can instantiate the prefab as I hope or it's not a good idea.</p>
  
  <p>Here is my code</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using UnityEngine.EventSystems;
  
  public class Purchase : MonoBehaviour,IPointerClickHandler
  {
      public GameObject purchasePanel;
      public GameObject panelPosition;
  
  public void OnPointerClick (PointerEventData eventData)
      {
  
          GameObject instantiatedPurchase = Instantiate(purchasePanel, panelPosition.transform.position,panelPosition.transform.rotation) as GameObject;  
      instantiatedPurchase.transform.SetParent(panelPosition.transform);
  }
  </code></pre>
  
  <p>}</p>