[英]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.