单击单个按钮时弹出一个弹出框
问题描述:
我想在按下按钮时显示弹出框。单击单个按钮时弹出一个弹出框
但现在它看起来像这样
我观看了关于如何使一个弹出时,按下按钮很多教程。
但他们都通过脚本弹出,而不是实例化预制件。
我不确定是否可以实例化预制件,因为我希望或它不是一个好主意。
这里是我的代码
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);
}
}
你的意思是不是每次都实例化它,只保留一个在场景中,并使用SetActive来控制它? –
是的,这就是他的意思。 – Savlon
确保您的数据透视也在预制中设置 – LumbusterTick