I have a bool array holding 6 (not sure the correct wording on this sorry)
how can i check if all are true but one?
lets say the bool is named myBool[ ];
myBool[1] = true; and so on. 1-4 = true, but 5 is false. I want something to happen this is the case. What would be the best way of handling that? OR would I just use an if statement for each bool in the array?
Sorry if this doesn’t make any since. I know what I want to do, I just don’t know how to word it in the correct way.
edit — maybe showing the code might help you understand what i’m aiming for–
using UnityEngine;
using System.Collections;
public class GameData : MonoBehaviour
{
//level select
public bool[] nextStage;
public int playedStage;
public int ammountOfLevels;
void Start()
{
ammountOfLevels = Application.levelCount;
Debug.Log(ammountOfLevels);
nextStage = new bool[ammountOfLevels];
nextStage[0] = true;
}
<-----code is truncated not to over flow you with unneeded items. NexLevelToLoad is called when stage has ended---->
IEnumerator NextLevelToLoad()
{
for (int i = 0;i < ammountOfLevels + 5; i++)
{
playedStage = Random.Range (0,ammountOfLevels);
Debug.Log (playedStage);
if(nextStage[playedStage])
{
playedStage = Random.Range (0,ammountOfLevels);
}
else
{
nextStage[playedStage] = true;
Application.LoadLevel(playedStage);
yield break;
}
So basically the last level (number 5) I always want to run after the first 4
nextStage[0] is automatically set to true since that stage is always played first.
How about telling us what you’re trying to achieve, instead of how you’re trying to do it?
If you’re using an array of bools to track unlocked levels, why not use a level completion counter instead? As in, just use an int that stores the number of the highest unlocked level, and compare against that to see if a given level is unlocked.
my goal is to have it randomly pick what level will be next. Once that level has been played I don’t want it to be picked again. Also I don’t want the last level to be chosen in the randomization and if it is I want it to be passed and try another random level.
Thanks for the reply Jeff. I think I will approach it a different way. I’m still going to use my bool array but subtract 1 from it and make sure my last level is always the last in the build. Then I’ll just check if all are true and if they are i’ll load the last level.
Going to use you’re code there and modify it a little and hope i’ll get it to do what i’m looking for. If you don’t mind answering my one question about your script there.
I’m very new to this (programming and unity), how would I set that foreach statement using my bool names? is it -
Might not be the best way to do this. But I’m still learning here. Only been using c# (or any language) for about a month now. But I do have to admit it is an addiction right now. It is a nice feeling when you have an idea and are able to get it to work. I just hope my over all ambition for this project is above my scope right now.