【发布时间】:2019-01-29 04:47:18
【问题描述】:
我在尝试隐藏作为面板的游戏对象时遇到了该错误。该面板包含一个画布和两个按钮。
最初,面板是隐藏的,脚本可以运行。当我尝试再次启用 panel.SetActive(true) 并返回到 panel.SetActive(false) 时出现错误。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class EquipmentSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{
public GameObject panel;
void Start()
{
GameObject panel= GameObject.FindGameObjectWithTag("panel");
}
public void OnPointerEnter(PointerEventData eventData)
{
GameObject panel= GameObject.FindGameObjectWithTag("panel");
panel.SetActive(false);
}
public void OnPointerExit(PointerEventData eventData)
{
GameObject panel = GameObject.FindGameObjectWithTag("panel");
panel.SetActive(true);
}
}
我删除了所有不必要的代码。我希望面板在悬停在菜单项上时打开和关闭,您知道,悬停功能在我的代码中有效。
【问题讨论】:
标签: unity3d gameobject