public void addStudents(MyPath mypath, SortedDictionary <int, int> pathToRoomIndex) { path = mypath; float distance = path.GetTotalDistance(); float spacing = distance / numStudents; studentLocations = new float[numStudents]; studentRooms = new Dictionary <int, List <int> > (); for (int studentIndex = 0; studentIndex < numStudents; studentIndex++) { float studentDist = 9f + studentIndex * distance * 0.9f / numStudents; studentLocations[studentIndex] = studentDist; int room = pathToRoomIndex[path.GetIndexAtDistance(studentDist)]; Debug.Log("Distance: " + studentDist + " Room:" + room); if (!studentRooms.ContainsKey(room)) { studentRooms.Add(room, new List <int>()); } //Debug.Log("Adding student " + studentIndex + " to room " + room + " Studentdist: " + studentDist + " totalDist: " + distance ); studentRooms[room].Add(studentIndex); } }
void FixedUpdate() { if (path == null) { return; } distance += speed * Time.deltaTime; if (distance > path.GetTotalDistance()) { distance = 0; } Vector3 position = path.GetPositonAlongPath(distance); Vector3 ahead = path.GetPositonAlongPath(distance + amountToLookAhead); railCamera.transform.position = position; railCamera.transform.LookAt(ahead); }