UNITY2D Instantiate GameObject in random Position on a Grid ?

I am doing a game, like a Breeding Frog Game.
(example: Cow evolution + Dragon city)

I don’t know how to do it, first I am making the Frog’s movement, they have to move in random direction.
But this is not really easy, and i didn’t found any Help about it.

My idea is to Create a grid… on this Grid, an invisible Object will spawn.
The Frog will go to the Object’s position, and after 4 to 7 seconds, the Objesct will desapear, and another one will spawn. etc …
So please help ^^ !

Not sure if I exactly understood it…

I would first create an vector2, then define the values like this:

position vector2(mathf.ceiltoint(random.range(xMin,xMax),mathf.ceiltoint(random.range(yMin,yMax));

You can instaniate it then, the “grid” as you call it would be in 1x1 blocks, the 5-7 seconds rule could either be done trough an invoke paired with an destroy after the given time.

The other option would an IEnumerator with an yield return new waitforseconds that destroys and calls the generation again

Note that the upper code probably has some typos in it, just play around.

I hope you will understand the draw ^^


1. The frog is on his default position.

2. The Object appears, and the forg will start to go to the object.
When he touchs the object, this one will be destroyed.

3. After 5 or 7 seconds, another Object will spawn, again at a random position.

4. and as the last time, the forg will follow the Object.