How to set a sprite's location to another sprite based on RNG.

Hi!

I’m having trouble setting up a script (C#) that, generates a random number from 1-5, then, based on that number moves the position of an object to another.

Basically i’m making a ‘mining’ type game where there is a hidden gem in one of 5 rocks on the screen, the objective is to get the gem within a time limit.
I think this is how you would set up the random number generator :

float loc = Random.RandomRange(1, 5);

‘loc’ being the variable it’s stored in.

but past that i’m not sure on where to go :confused:

i think it would be something like:

if(loc <= 1){
			gem.transform.position = transform.TransformPoint (0, 0, 0);
		}

etc. but yeah, im not sure xD

Thanks

I would create a public gameobject array and place several gameobjects in the scene (where the gem could be) and add those in the inspector to the array. then I would go:

gem.transform.position = positionsArray[RandomRange(0, positionsArray.Length)].transform.position;