简体   繁体   English

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

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

In my game, I plan to make tutorials appear for my game.在我的游戏中,我计划为我的游戏制作教程。 As in you press T to make the tutorial window appear and press Q and E to cycle through multiple tutorial images.正如你按 T 使教程 window 出现,然后按 Q 和 E 循环显示多个教程图像。 The tutorial images are game objects.教程图像是游戏对象。 So, if I got 10 tutorial images.. and need only ONE of them active at a time (while the others are deactivated), how do I do it?所以,如果我有 10 张教程图片……并且一次只需要激活其中一张(而其他的则停用),我该怎么做?

I have tried this:我试过这个:

tutorialBubbles[] is the array of game objects. 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);   
                }
            }
        }

You can define some integer values for demonstrate which ArrayID wont be inclueded.您可以定义一些 integer 值来演示哪些 ArrayID 不会被包含在内。 For example:例如:

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);
                    }
                    
                }
            }

I defined a int(exceptArrayId) for this example.我为这个例子定义了一个 int(exceptArrayId)。

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

相关问题 如何停用列表中除当前正在使用的相机之外的所有相机? - how do I deactivate all cameras in a list except for the one that is currently in use? 仅按下一个按钮后,如何停用 Vuforia 中的所有虚拟按钮? - How do I deactivate all the virtual buttons in Vuforia after pressing just one? 更改对象数组中的一个元素会更改所有元素,C#,如何按值分配对象 - Changing one element in array of objects changes all elements, c#, how do I assign objects by value 如何让一个游戏对象的 x 位置等于另一个对象的 x 位置? (2D Unity 游戏) - How do I get one game objects x position to equal another objects x position? (2D Unity Game) 如何正确检测游戏对象? - How do I properly detect game objects? innertext返回所有子文本和自身文本。 除了一个孩子的文字,我该怎么办 - innertext return all the child and self text. how do i except one child text 如何为所有同级游戏对象禁用碰撞? - How can I disable collisions for all sibling game objects? 如何将数组中的所有文件路径移动到一个目录 - How do I move all the file paths in an array to one directory 如何制作一系列游戏对象 - How to make an array of game objects 如何在 Unity 中启用和禁用多个游戏对象? - How do I enable and disable multiple game objects in Unity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM