Simple 2 Array bool Comprasion
Hi All!
I've been working on a problem for 3 days. I've searched the forums and unity answers but even though it's a simple question, I couldn't find any results.
Issue details;
I have a player object that contains some items, and incoming object, which also contains some items. I just want to compare the contained objects are active or not.
Something like: If playerObject[0] is active AND incomingObject[0] is active, if playerObject[1] is NOT active AND incomingObject[1] is NOT active. etc...
So BOTH should be TRUE or BOTH should be FALSE. Except these conditions, it has to return false.
Here is what I wrote and didn't work; (gameObject[0] instead of gameObject[i] because that's the closest one to the player)
public void CheckFF()
{
gameObjects = GameObject.FindGameObjectsWithTag("StartIncoming");
checker = new bool[core.checkActive.Length];
for (int i = 0; i < core.checkActive.Length; i++)
{
if (core.checkActive[i] == true && gameObjects[0].GetComponent<Incoming>().isActive[i] == true)
{
checker[i] = true;
}
else if (core.checkActive[i] == false && gameObjects[0].GetComponent<Incoming>().isActive[i] == false)
{
checker[i] = false;
}
else
{
}
}
if (isItGoodToGo())
{
print("GOOD TO GO!");
}
}
private bool isItGoodToGo()
{
for (int i = 0; i < checker.Length; i++)
{
if (checker[i] == true)
{
return true;
}
}
return false;
}
Answer by Tarexelion · Dec 10, 2019 at 08:44 AM
If anyone looking for the answer, I've solved it with:
bool fastForwardable = incomingActive.SequenceEqual(checkActive);
Your answer
Follow this Question
Related Questions
I am trying to display two scores and use them to trigger events. 1 Answer
How do I Effect a whole Array of GameObjects' Scripted Boolean? 0 Answers
If script not working as expected - camera switch 1 Answer
boolean not switching to false. 0 Answers
Not all code paths return a value error. Fixing the error breaks my function. Ideas? 1 Answer