Simplifying the order of code.

So I have an if statement that executes based on if certain integers meet the proper conditions, but I don’t want the order of which to matter. Hopefully the code explains itself better than I can:

if (item1 == 7 && item2 == 8 || item1 == 8 && item2 == 7)
{
    successful = true;
    Debug.Log("Works");
}

I’m looking for a solution now so I don’t have to manually code it in the future where I’ll have item1-6 and every possible order the integers could appear in…

There’s probably a simple solution to this, but It has exceeded me.

It’s easy to do it with LINQ and with the .Contains method. All you have to do is store the numbers that you’d like to be checked and then write the if statement. If there would be too many items to check then I’d suggest you to put the items in a List, iterate through them and check it one by one.

You could also use a boolean to check if any of them fail or pass and at the end of the cycle based on the boolean (and some other variables) you can decide what to do with the outcome.

Here’s the script:

using System.Linq;
using UnityEngine;

public class Example : MonoBehaviour {
	bool successful = false;
	int[] numbersToCheck = { 7, 8, 9, 10 };

	void CheckNumbers() {
		if (numbersToCheck.Contains(item1) || numbersToCheck.Contains(item2) || numbersToCheck.Contains(item3) || ...) {
			successful = true;
     		Debug.Log("Works");
		}
	}
}