SOLVED! - Pick Number != These Other Numbers

So I’m putting together a script that will pick a number that does not equal other numbers that are based on an instance. I’ve put together a scrip that does what I think it should do, however it returns a number it should not.

Code Summary: There is a range of numbers from 0 to 4. I’d like it to shuffle through these numbers and pick one that does not equal another set of numbers. However, it still picks the incorrect number.

do{var pick = Random.Range(0,5;}
				
while(pick != Number0 && pick != Number1 && pick != Number2 && pick != Number3 && pick != Number4);

6766-unity01.jpg

The correct answer in this case, would be 0 or 1, but it picks 3.

I think your while condition should be the other way around. As long as what is inside is true the condition repeats. I guess you want the invert effect.

SOLVED IT!

Here is the code that does what I intended:

			while(picked == false)
			{
				var pick = Random.Range(0,5);
				
				if(pick != number0 && pick != number1 && pick != number2 && pick != number3 && pick != number4)
				{
					yield pick;
					picked = true;
				}
			}