繁体   English   中英

我如何停用阵列中除 ONE 之外的所有游戏对象?

[英]How do I deactivate all game objects in an array except ONE?

在我的游戏中,我计划为我的游戏制作教程。 正如你按 T 使教程 window 出现,然后按 Q 和 E 循环显示多个教程图像。 教程图像是游戏对象。 所以,如果我有 10 张教程图片……并且一次只需要激活其中一张(而其他的则停用),我该怎么做?

我试过这个:

tutorialBubbles[]是游戏对象数组。

public GameObject[] tutorialBubbles; //delete the above one if we're going with multiple 
bool tutorialNeeded;

void checkIfTutorialNeeded() {
    
        if (Input.GetKeyDown(KeyCode.T))
        {
            tutorialNeeded = true;
        }

        if(!tutorialNeeded && Input.GetKeyDown(KeyCode.T)){

            tutorialBubbles[0].SetActive(false);
        }

        if (tutorialNeeded)
        {
            tutorialBubbles[0].SetActive(true);
            

            if (Input.GetKeyDown(KeyCode.G))
            {
                tutorialBubbles[1].SetActive(false);

                for (int i = 2; i < tutorialBubbles.Length; i++)
                {
                    tutorialBubbles[i].SetActive(true);   
                }
            }
        }

您可以定义一些 integer 值来演示哪些 ArrayID 不会被包含在内。 例如:

public GameObject[] tutorialBubbles; //delete the above one if we're going with multiple 
bool tutorialNeeded;
int exceptArrayId;
if (Input.GetKeyDown(KeyCode.G))
            {
                tutorialBubbles[1].SetActive(false);
                exceptArrayId = 1;

                for (int i = 0; i < tutorialBubbles.Length; i++)
                {
                    if(i == exceptArrayId)
                    {
                        tutorialBubbles[i].SetActive(false);
                    }
                    else
                    {
                        tutorialBubbles[i].SetActive(false);
                    }
                    
                }
            }

我为这个例子定义了一个 int(exceptArrayId)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM