我被困在试图让一张卡从数组中出现,而其他卡保持不活动。

问题描述 投票:0回答:1

我有一个由12张牌组成的数组,我被困在了如何让一张牌从数组中出现,而其余的牌却一直处于非活动状态。

string name = "Card_" 
int deckcards;
public void shuffle_Deck()
    {
        //runs a random selection from the range and updates the namespace of the gametag
        deckcards = Random.Range(1, 13);
        tagName = name + deckcards;

        //printing to the console
        Debug.Log(tagName);
        //calling the gametag of the gameobject and setting the rest of the objects invisible;

        foreach (GameObject array in gameArray)
        {
            GameObject.FindWithTag(tagName).SetActive(true);
         //How do i set the rest to false


        }
c# visual-studio unity3d
1个回答
1
投票

如果你使用迭代整个牌组,我认为答案是。

foreach (GameObject array in gameArray)
{
    if(array.CompareTag(tagName))
    {
        array.SetActive(true);
    } 
    else 
    {
        array.SetActive(false);
    }
}

我想这可能会解决这个问题

© www.soinside.com 2019 - 2024. All rights reserved.