C# 不确定为什么逻辑不能激活游戏对象
我的逻辑在过去是有效的,但不清楚为什么这不起作用来激活我的游戏对象。这尤其令人费解,因为我没有错误。字段匹配正确,我没有前面提到的错误。这用于库存系统C# 不确定为什么逻辑不能激活游戏对象,c#,unity3d,C#,Unity3d,我的逻辑在过去是有效的,但不清楚为什么这不起作用来激活我的游戏对象。这尤其令人费解,因为我没有错误。字段匹配正确,我没有前面提到的错误。这用于库存系统 public class addToArtMode : MonoBehaviour { public bool On = true; public GameObject slotPanel; void Start() { this.GetComponent<Button>().on
public class addToArtMode : MonoBehaviour
{
public bool On = true;
public GameObject slotPanel;
void Start()
{
this.GetComponent<Button>().onClick.AddListener(() => AddToArtMode());
slotPanel = GameObject.Find("Slot Panel");
}
public void AddToArtMode()
{
if (On)
{
Debug.Log("ID'ing ");
slotPanel = GameObject.Find("Slot Panel");
foreach (Transform child in slotPanel.transform)
{
var parentName = this.GetComponentInParent<ArtBrowseContentInformation>().NameofArt;
var childname = child.GetComponent<InventoryContentInfo>().NameofArt;
if (childname == parentName)
{
child.gameObject.SetActive(true);
On = false;
Debug.Log("what ");
}
else
{
Off();
}
}
void Off()
{
foreach (Transform child in slotPanel.transform)
{
var parentName = this.GetComponentInParent<ArtBrowseContentInformation>().NameofArt;
var childname = child.GetComponent<InventoryContentInfo>().NameofArt;
if (childname == parentName)
{
Debug.Log("the heck");
child.gameObject.SetActive(false);
On = true;
}
}
}
}
}
}
}
try gameObject.enabled=false/true 您是否设置了断点并检查了状态?childname==parentName是一条语句,只有您知道数据是什么。没有人能帮忙。除非你有具体的数据,但你无法弄清楚。若不允许使用断点,将其打印到控制台可能会有所帮助。