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]; } }