Storing the Position Generated by Random.Range

In my game there are 6 spawn points - 3 on the left and 3 on the right. I have my left spawner script randomly choose 1 of the 3 spawn points on the left and then spawn a cross hair (which acts as a warning). The cross hair has an animation attached to it that moves right and then back (might have something to do with issue). After the warning a bullet spawns and moves across the screen. I can get both prefabs to instantiate, but instantiating them in the same position is not working out. I need to find a way to reference the spawn point chosen for the cross hairs and then reuse the randomly chosen spawnpoint for my bullet. I’ve tried a couple things, but haven’t been able to get it to work properly.

Here’s my code:

using UnityEngine;
using System.Collections;

public class BulletSpawnerLeft : MonoBehaviour {

	public Transform [] spawnPoints;

	//public Transform [] crossHairSpawnPoints;
	public float spawnTime;

	public GameObject pistolBullet;
	public GameObject[] pistolAndShotgunBullet;
	public GameObject[] pistolShotgunAndSniperBullet;
	public GameObject[] pistolShotgunSniperAndRocketBullet;

	//public static bool isActive = false;

	public GameObject crossHairs;

	private int level1 = 0;
	private int level2 = 0;
	private int level3 = 0;

	void Start(){

		spawnTime = 7f;
		InvokeRepeating ("SpawnPistolBullet", spawnTime, spawnTime);

	}

	void Update(){

		if (ScoreManager.scoreCount >= 5000 && ScoreManager.scoreCount < 10000 && level1 == 0) {

			level1++;
			spawnTime = 6f;
			CancelInvoke ("SpawnPistolBullet");
			InvokeRepeating ("SpawnPistolAndShotgunBullet", spawnTime, spawnTime);

		}

		if (ScoreManager.scoreCount >= 10000 && ScoreManager.scoreCount < 20000 && level2 == 0) {

			level2++;
			spawnTime = 4f;
			CancelInvoke ("SpawnPistolAndShotgunBullet");
			InvokeRepeating ("SpawnPistolShotgunAndSniperBullet", spawnTime, spawnTime);

		}

		if (ScoreManager.scoreCount > 20000 && level3 == 0) {

			level3++;
			spawnTime = 2f;
			CancelInvoke ("SpawnPistolShotgunAndSniperBullet");
			InvokeRepeating ("SpawnPistolShotgunSniperAndRocketBullet", spawnTime, spawnTime);

		}


	}


	void SpawnPistolBullet(){

		int spawnIndex= Random.Range (0, spawnPoints.Length);
		//Transform crossHairs;
		//crossHairs = Random.Range (0, spawnPoints.Length);
		GameObject crossHairs1;
		crossHairs1 = Instantiate (crossHairs, spawnPoints[spawnIndex].position, spawnPoints[spawnIndex].rotation)as GameObject;

		//isActive = true;

		if (crossHairs1.transform.position == spawnPoints[0].transform.position) {
			
			Instantiate (pistolBullet, crossHairs1.transform.position, crossHairs1.transform.rotation);

		}

		else if (crossHairs1.transform.position == spawnPoints[1].transform.position) {

			Instantiate (pistolBullet, crossHairs1.transform.position, crossHairs1.transform.rotation);

		}

		else if (crossHairs1.transform.position == spawnPoints[2].transform.position) {

			Instantiate (pistolBullet, crossHairs1.transform.position, crossHairs1.transform.rotation);

		}

		/*if (spawnPoints [0]) {

			Instantiate (crossHairs, crossHairSpawnPoints [0].position, crossHairSpawnPoints [0].rotation);
			Destroy (crossHairs, 2);
		}*/



	}

	void SpawnPistolAndShotgunBullet(){

		int spawnIndex = Random.Range (0, spawnPoints.Length);
		int objectIndex = Random.Range (0, pistolAndShotgunBullet.Length);
		Instantiate (pistolAndShotgunBullet[objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );

	}

	void SpawnPistolShotgunAndSniperBullet(){

		int spawnIndex = Random.Range (0, spawnPoints.Length);
		int objectIndex = Random.Range (0, pistolShotgunAndSniperBullet.Length);
		Instantiate (pistolShotgunAndSniperBullet[objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );

	}

	void SpawnPistolShotgunSniperAndRocketBullet(){

		int spawnIndex = Random.Range (0, spawnPoints.Length);
		int objectIndex = Random.Range (0, pistolShotgunSniperAndRocketBullet.Length);
		Instantiate (pistolShotgunSniperAndRocketBullet[objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );

	}

}

I may not have read your question right, but how about instantiating the bullet from the cross hair gameobject? Make a script that Instantiates the bullet and attach it to the animation you’re instantiating.

private Vector3 lastspawnpointused;
store the last spawnpoint used based off which spawnpoint was chosen

lastspawnpointused = spawnPoints[spawnIndex].position;

now whenever you need to reference the last spawnpoint

bullet.position = lastspawnpointused;