Coin Genration Algorithm in Runner Game

I’m making a runner game sequel like subway surfer. Here are the following mechanics I’ve done:

  • Platform Generation

  • Enemy Generation

  • Power up Generation

  • Point Generation

    Out of these I have problem in generating points algorithm. I have a vision of having points like Subway Surfer game. And right now I was just able to put them randomly on the lanes. Here is my code for Random distribution in lanes.

public void PositionCoins(Vector3 position)
{
int maxZ = (int)position.z + 17;
int minZ = (int)position.z - 59;
for(int i = 0;i < coinList.Count;i++)
{
int randomZ = Random.Range(minZ,maxZ);

		int randomLane = Random.Range(1,5);
		int lane;
		if(!coinList*.activeInHierarchy)*
  •   	{*
    
  •   		if(randomLane == 1)*
    
  •   		{*
    

_ coinList*.transform.position = new Vector3(-1.35f,1.2f,randomZ);_
_
}_
_
else if(randomLane == 2)_
_
{_
_ coinList.transform.position = new Vector3(0.05f,1.2f, randomZ);
}
else if(randomLane == 3)
{
coinList.transform.position = new Vector3(1.45f,1.2f, randomZ);
}
else if(randomLane == 4)
{
coinList.transform.position = new Vector3(2.85f,1.2f, randomZ);
}
coinList.SetActive(true);
}
}
}*_

Now what I want is coins like Subway Surfer randomly distributed in a group of 4-5 coins, equally spaced. Any help is appreciated.

I am not reviewing your code but I will explain what I did in my game a Year ago
I made a group of prefabs of coins with onTrigger in it and then randomly instantiate those prefabs with equal spacing

which worked perfectly .