Instantiate prefab and send it required game objects

I’m working on a game which will have cars randomly generate and follow a path. I have the cars prefabbed and I am working on a C# script that will allow me to randomly generate a car, and have it follow the path that it is assigned to. I can send the cars to the correct start point but I am not sure how to send the car the path. For testing purposes I have the spawning tied to the space bar.

static public int carListSize;
static public int pathsSize = 4;
public GameObject[] paths = new GameObject[pathsSize];
public GameObject[] pathStartPoint = new GameObject[pathsSize];
public GameObject[] carPrefabs = new GameObject[carListSize];
public int num;
FollowPath newObj;

void Update()
{
    if (Input.GetKeyDown("space"))
    {
        num = Random.Range(0, pathsSize);
        newObj = Instantiate(carPrefabs[0],
        pathStartPoint[num].transform.position, Quaternion.Euler(0, 180, 0));
        newObj.path = paths[num];
    }
}

You have to access the script that’s attached to the newObj. You were trying to assign your prefabs as a FollowPath script. Try this…

static public int carListSize;
static public int pathsSize = 4;
public GameObject[] paths = new GameObject[pathsSize];
public GameObject[] pathStartPoint = new GameObject[pathsSize];
public GameObject[] carPrefabs = new GameObject[carListSize];
public int num;
//I took out the newObj declaration here...

void Update()
{
  if (Input.GetKeyDown("space"))
  {
    num = Random.Range(0, pathsSize);
    //here, we create newObj as a GameObject
    GameObject newObj = (GameObject)Instantiate(carPrefabs[0],
        pathStartPoint[num].transform.position, Quaternion.Euler(0, 180, 0));
        //...and here we Get the Component, the FollowPath script, of newObj, then assign the variable path
        newObj.GetComponent<FollowPath>().path = paths[num];
   }
}