Continuing on from comments below.
Each section has a script attached to it which does 2 things (called ThisSectionInfoManager).
- Finds its Endpoint
- Contains a public Transform array storing the path points positions, etc.The array is called ‘RailMarkersList’)
The code for this is as follows:
public class ThisSectionInfoManager : MonoBehaviour
{
public Transform EndPoint;
public Transform[] RailMarkersList;
void Start ()
{
EndPoint = transform.Find("sectionend");
}
void Update ()
{
}
}
------
3 sections are maintained at all times with the camera starting in the first [0]. Once it approaches the start-point of the following section [1], a new section is generated and the first removed. In this way, the camera is always just entering the first section.
Now, a script called SectionManager generates and aligns the new section at the end. At the same time, the script that deals with the path following (CameraPathFollow) accesses the SectionManager script to find out what the first section of the array is (CurrentlyLaidSectionList[0]). It then goes on to access that section’s script mentioned earlier (ThisSectionInfoManager) to copy its path points array (called RailMarkersList) into an array here (called Section_1_path, for instance). it then goes ahead and follows the path as we talked about below.
The CamerPathFollow script is as follows;
public class CameraPathFollow : MonoBehaviour
{
// Tranform arrays to hold the empty objects that form the path of the camera.
// Points dragged in from Inspector - One array for each section.
public Transform[] Section_1_path;
public Transform[] Section_2_path;
public Transform[] Section_3_path;
public Transform[] Section_4_path;
public Transform[] Section_5_path;
public Transform[] Section_6_path;
//
float t = 0;
// Variable to hold the tag of the section that the camera is in front of [0]
private Transform sectionToFollow;
// Reference to the Parking Lot object
private GameObject parkingLotObj;
//private SmoothQuaternion sr = new Quaternion();
private SmoothQuaternion sr = new SmoothQuaternion();
public float CameraSpeed;
void Start ()
{
// Gain access to the Parking Lot object
parkingLotObj = GameObject.Find("Parking Lot");
sr = transform.rotation;
sr.Duration = 0.5f;
}
void Update()
{
// Set the nextSection variable to hold the tag of the section in the second element [1] of the
// CurrentlyLaidSectionList List - this is the one that the camera is always about to enter
sectionToFollow = parkingLotObj.GetComponent<SectionManager>().CurrentlyLaidSectionList[0];
// use swtih statement to decide which Transform array above to use for the path of the camera,
// depending on which section is in CurrentlyLaidSectionList[1] at the time.
switch (sectionToFollow.tag)
{
case "Section_1":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_1_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_1_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// Debug.Log("Entering Section 1");
break;
}
case "Section_2":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_2_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_2_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// Debug.Log("Entering Section 2");
break;
}
case "Section_3":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_3_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_3_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// Debug.Log("Entering Section 3");
break;
}
case "Section_4":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_4_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_4_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// Debug.Log("Entering Section 4");
break;
}
case "Section_5":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_5_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_5_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
// Section_5_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_5_path, transform.position, ref t, CameraSpeed);
// Debug.Log("Entering Section 5");
break;
}
case "Section_6":
{
Quaternion q = new Quaternion();
// Copy the RailMarkersList into our array here so that the camera has the positions of the
// markers after the section has been positioned
Section_6_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
sr.Value = q;
transform.rotation = sr;
// transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, 300f);
//transform.rotation = Spline.RotationBetween(Section_6_path, );
// Debug.Log("Entering Section 6");
break;
}
default:
return;
}// ends switch
}