[C#] Creating falling coins

So I’ve managed to work up this CoinPooler script for my game. Issue I’m having is none of the coins are spawning on the x axis, they are all clumped behind on another making it impossible for a player to collect the coins. Any suggestions on how to fix this? My code will be listed below.

Yes, I’m using a form of ObjectPooling and Instantiate & Destroy. I tried using normal object pooling but I kept having problems with it when I was destroying the previous game objects.

    private GameObject[] pooledBronze;
    public GameObject silverCoin;
    public GameObject goldCoin;

    public GameController gameControl;

    public GameObject bronzePrefab;

    private int bronzeCoinAmount = 40;
    private int silverCoinAmount = 2;
    private int goldCoinAmount = 1;

    private int currentBronzeCoin = 0;
    private int currentSilverCoin = 0;
    private int currentGoldCoin = 0;

    public float coinObjMin = -3f;
    public float coinObjMax = 9f;
    private float spawnYPos = 10;
    public float timeToSpawn = 0f;
    private Vector2 coinPoolPos = new Vector2(-3, 10);


    // Use this for initialization
    void Start () {
        gameControl.GetComponent<GameController>();

    }
	
	// Update is called once per frame
	void FixedUpdate () {

        timeToSpawn += 2.0f * Time.deltaTime;

        if (timeToSpawn >= 9f)
        {
            spawnCoins();
            timeToSpawn = 0f;
        }

    }

    private void spawnCoins()
    {
        pooledBronze = new GameObject[bronzeCoinAmount];
        for (int i = 0; i < bronzeCoinAmount; i++)
        {
            pooledBronze *= (GameObject)Instantiate(bronzePrefab, coinPoolPos, Quaternion.identity);*

}
if (gameControl.gameOver == false && gameControl.gameStart && timeToSpawn >= 60.0f)
{
float spawnXPos = Random.Range(coinObjMin, coinObjMax);
pooledBronze[currentBronzeCoin].transform.position = new Vector2(spawnXPos, spawnYPos);
currentBronzeCoin++;

if(currentBronzeCoin >= bronzeCoinAmount)
{
currentBronzeCoin = 0;
}

if(currentBronzeCoin == 0)
{
spawnCoins();
}
}
}

There’s a lot in there to go over…
i think its been done quite poorly so maybe delete it and re-write this in a better way…

    private GameObject[] pooledBronze;
	public GameObject silverCoin;
	public GameObject goldCoin;

	public GameController gameControl;

	public GameObject bronzePrefab;

	private int bronzeCoinAmount = 40;
	private int silverCoinAmount = 2;
	private int goldCoinAmount = 1;

	private int currentBronzeCoin = 0;
	private int currentSilverCoin = 0;
	private int currentGoldCoin = 0;

	public float coinObjMin = -3f;
	public float coinObjMax = 9f;
	private float spawnYPos = 10;
	public float timeToSpawn = 0f;
	private Vector2 coinPoolPos = new Vector2(-3, 10);


	// Use this for initialization
	void Start () {
		// this does nothing. it gets the component but
		// does nothing with it nor assign it to something
		gameControl.GetComponent<GameController>();
	}

	// Update is called once per frame
	void FixedUpdate () {

		timeToSpawn += 2.0f * Time.deltaTime;

		if (timeToSpawn >= 9f)
		{
			spawnCoins();
			timeToSpawn = 0f;
		}

	}

	// overall this method is quite senseless and should be re-done
	private void spawnCoins()
	{
		var thing = new GameObject[0];
		pooledBronze = new GameObject[bronzeCoinAmount];
		for (int i = 0; i < bronzeCoinAmount; i++)
		{
			// coinPoolPos never changes which is why they all spawn in the same spot.
			pooledBronze *= (GameObject)Instantiate(bronzePrefab, coinPoolPos, Quaternion.identity);*
  •  }*
    
  •  // this block below will never get called.*
    
  •  // in void FixedUpdate () if timeToSpawn >= 9 then you spawn and then set it to 0*
    
  •  // therefor it will never be > 60.*
    
  •  if (gameControl.gameOver == false && gameControl.gameStart && timeToSpawn >= 60.0f)*
    
  •  {*
    
  •  	float spawnXPos = Random.Range(coinObjMin, coinObjMax);*
    
  •  	pooledBronze[currentBronzeCoin].transform.position = new Vector2(spawnXPos, spawnYPos);*
    
  •  	currentBronzeCoin++;*
    
  •  	if(currentBronzeCoin >= bronzeCoinAmount)*
    
  •  	{*
    
  •  		currentBronzeCoin = 0;*
    
  •  	}*
    
  •  	// if the statement above is called then this will be called so*
    
  •  	// factor this out.*
    
  •  	if(currentBronzeCoin == 0)*
    
  •  	{*
    
  •  		// this could end up being a recurring method == not good.*
    
  •  		spawnCoins();*
    
  •  	}*
    
  •  	// this is a combination of the above 2 if statements into one simple one.*
    
  •  	if(currentBronzeCoin >= bronzeCoinAmount || currentBronzeCoin == 0)*
    
  •  	{*
    
  •  		currentBronzeCoin = 0;*
    
  •  		spawnCoins();*
    
  •  	}*
    
  •  }*
    
  • }*