03-06-2019, 04:43 AM
Hi there,
I'm instantiating a spawned object during runtime, then adding a Spline Controller script to it and assigning its Spline via code. This part is all working great. However, under the Events area of the Spline Controller script (viewed in the Inspector), I need to then assign new values for "On Control Point Reached" and "On End Reached", both the listener itself and the Event Handler designation. This where I get stuck.
I know I'm close... it should be something like this:
The question marks are where I get stuck. How do I add and assign a new "OnControlPointReached" and "OnEndReached" here?
I've also attached a photo of what I WANT it to look like. In the meantime, I've created a workaround where I assign these values to the actual Resource so they are already assigned when they are Instantiated. But this is what I'm trying to achieve (attached).
Any advice? I'm stuck!
Thank you!
I'm instantiating a spawned object during runtime, then adding a Spline Controller script to it and assigning its Spline via code. This part is all working great. However, under the Events area of the Spline Controller script (viewed in the Inspector), I need to then assign new values for "On Control Point Reached" and "On End Reached", both the listener itself and the Event Handler designation. This where I get stuck.
I know I'm close... it should be something like this:
Code:
public int numberOfVehiclesinFleet = 4;
public List<GameObject> newVehicleFleet = new List<GameObject>;
void Start(){
CreateNewVehicles();
}
void CreateNewVehicles(){
for (int i = 0; i < numberOfVehiclesInFleet, i++){
GameObject newVehicle = Instantiate (Resources.Load("Vehicle", typeof(GameObject)) as GameObject);
newVehicleFleet.Add (newVehicle);
}
for (int i = 0; i < numberOfVehiclesInFleet; i++){
newVehiclefleet[i].AddComponent<SplineController>();
newVehicleFleet[i].AddComponent<CurvyEventHandler>();
newVehicleFleet[i].GetComponent<SplineController>().enabled = true;
newVehicleFleet[i].GetComponent<SplineController>().OnControlPointReached(??????????)
}
}
The question marks are where I get stuck. How do I add and assign a new "OnControlPointReached" and "OnEndReached" here?
I've also attached a photo of what I WANT it to look like. In the meantime, I've created a workaround where I assign these values to the actual Resource so they are already assigned when they are Instantiated. But this is what I'm trying to achieve (attached).
Any advice? I'm stuck!
Thank you!