我有一个由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
}
如果你使用迭代整个牌组,我认为答案是。
foreach (GameObject array in gameArray)
{
if(array.CompareTag(tagName))
{
array.SetActive(true);
}
else
{
array.SetActive(false);
}
}
我想这可能会解决这个问题