Reputation: 11
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. 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?
I have tried this:
tutorialBubbles[]
is the array of game objects.
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);
}
}
}
Upvotes: 1
Views: 460
Reputation:
You can define some integer values for demonstrate which ArrayID wont be inclueded. 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.
Upvotes: 1