You are correct that you should have four “marker objects” (simply, empty game objects) which are the positions.
If I’m not mistaken you’re just wondering the basic programming question of how to pick two of these randomly, is this correct?
I will actually go ahead and tell you the correct programming solution for this - so it’s a world first for this list.
So you have the index numbers zero through three. You’re with me so far right?
Notice there are four (count) such numbers.
var howManyNumbersDoIHave : int = 4;
No problem so far right?
Now your solution will be TWO INDEX numbers. Correct right?
var theFirstResultIndex : int
var theSecondResultIndex : int
The first one is easy.
theFirstResultIndex = Radom.Range( 0, howManyNumbersDoIHave );
{Aside – Note that with Random.Range, the second argument IS THE TOTAL COUNT, it is not the “last number you want”. So for example Random.Range(931, 1550) would START at 931, and there would be a possibility of 1550 numbers in total. So note that Random.Range(0,2) would give you either a “0” or a “1”. So hopefully that’s clear.}
Now here’s how you do the second one. You travel in a loop around from where you are (the first one) but only as far as you don’t pass the first one again.
var howFarToTravelAtMostInALoop : int;
howFarToTravelAtMostInALoop = howManyNumbersDoIHave - 1;
Makes sense right?
So you need a random number from ONE to and including howFarToTravelAtMostInALoop.
var howFarToTravel : int;
Let’s pick a random number from 1 inclusive up to and including howFarToTravelAtMostInALoop
howFarToTravel = Random.Range( 1, howFarToTravelAtMostInALoop );
In your example this will give you either a 1, 2 or a 3
var whereILandedAfterTravellingInALoop : int;
Here’s a big secret.
whereILandedAfterTravellingInALoop =
theFirstResultIndex + howFarToTravel;
but that could “go past the end” am I right? So you have to do this:
whereILandedAfterTravellingInALoop =
whereILandedAfterTravellingInALoop % howManyNumbersDoIHave;
theSecondResultIndex = whereILandedAfterTravellingInALoop;
Notice the magical “modulo” (arguably, “modulus”) symbol. You can learn about this easily by doing a four-year computer science / pure math double major course, so go do that.
All you need to know is it will make you travel in a loop.
Et Voila, you have the two answers:
Debug.Log("the two safe and different numbers are "
+ theFirstResultIndex +" "+ theSecondResultIndex);
Any other method for doing this is wrong. Hopefully nobody ever has to explain this again in this universe, and i hope it helps!
Regarding how to turn on and off the array, it’s this simple …
“set up an array for the empty game objects…” yes, that’s correct
var myFourItems : GameObject;
in the editor, drag the four items there. Then just do this
myFourItems[theFirstResultIndex].SetActive(false);
myFourItems[theSecondResultIndex].SetActive(false);
(or, if you wanted, turn the renderer on/off … whatever is relevant to you.)
It could be you further more have complicated functions on those objects, so your script might be called “MyScript.js” which is attached to each of the four objects and which has functions like “MyFunction()”. To access those, just do this…
myFourItems[x].GetComponent<MyScript>.YourFunction();
Relatedly, I also direct you to this long answer which is a basic in stuff like this; some of the example code for “accessing stuff in Lists etc” may be relevant here. Keeping track of items in a pool? - Unity Answers