![](/img/trans.png)
[英]how do I deactivate all cameras in a list except for the one that is currently in use?
[英]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.