Intantiate problems

I’m trying to generate random obstacles for a temple runner type game, the main problem though is the issue surrounding “temp”.

I’m crazy new at scripting so anyhelp would be great. Here’s the script so far.

using UnityEngine;
using System.Collections;

public class RockSpawnScript : MonoBehaviour {

	public GameObject Rock_001;
	public GameObject Rock_002;
	public GameObject Rock_003;
	public GameObject Rock_004;
	public GameObject Rock_005;

	float timeElapsed = 0;
	float spawnCycle = 3f;
	int chooser = Random.Range (1,5);

	
	void Update () {
		timeElapsed += Time.deltaTime;
		if (timeElapsed > spawnCycle)
		{

		Vector3 pos = temp.transform.position;
	
switch (chooser)
{
case 1:
		temp = (GameObject)Instantiate(Rock_001);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
case 2:
		temp = (GameObject)Instantiate(Rock_002);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
case 3:
		temp = (GameObject)Instantiate(Rock_003);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
case 4:
		temp = (GameObject)Instantiate(Rock_004);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
case 5:
		temp = (GameObject)Instantiate(Rock_005);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
default:
		temp = (GameObject)Instantiate(Rock_001);
		pos = temp.transform.position;
		temp.transform.position = new Vector3(Random.Range(20, -20), pos.y, pos.z);
	break;
			}
		}
	}
}

I took the liberty of cleaning your code up a bit. This should work, and I tell you what I changed after the //

using UnityEngine;
using System.Collections;


public class RockSpawnScript : MonoBehaviour {
	
	public GameObject[] rocks;

	//I deleted all the single rock gameobjects. You don't need them when you have
    //an array called rocks where you can put them all inside in the editor

	float timeElapsed = 0; //Changed this to 0 because this is your "counter" and it should start at 0
	float spawnCycle = 5f;
	
	void Update () //You wrote update with a lowercase u here. So that's why it didn't work. Always remember to Capitalize methods.
		
	{
		timeElapsed += Time.deltaTime;
		if (timeElapsed > spawnCycle)
		{
			timeElapsed = 0; //Once it becomes true that timeElapsed is higher than our spawnCycle value, we reset it back to 0 so it can begin counting up again from 0.
			GameObject temp = Instantiate (rocks[Random.Range (0,rocks.Length)]) as GameObject; //Tells it to find a random rock between 0(the first rock in the rocks array) and the total length of your array.
			Vector3 pos = temp.transform.position;
			temp.transform.position = new Vector3(Random.Range(14, -14), pos.y, pos.z);
		}
	}
}