Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不确定为什么逻辑不能激活游戏对象_C#_Unity3d - Fatal编程技术网

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是一条语句,只有您知道数据是什么。没有人能帮忙。除非你有具体的数据,但你无法弄清楚。若不允许使用断点,将其打印到控制台可能会有所帮助。