I am trying to make multiple (Here only 2) object follow a spline path using spline animate component. here both spline animate has duration of 10. I also need to rotate the path runtime so spline animate objects moves along with them . I created this script for it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Splines;
public class SplineAndFollower : MonoBehaviour
{
public Transform parent;
public SplineAnimate a1, a2;
private void OnEnable()
{
StartCoroutine(SAnimate());
}
private void LateUpdate()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
parent.eulerAngles += new Vector3(0, 0, Time.deltaTime * 50);
}
else if (Input.GetKey(KeyCode.RightArrow))
{
parent.eulerAngles -= new Vector3(0, 0, Time.deltaTime * 50);
}
}
private IEnumerator SAnimate()
{
float t = 0;
while (t < 10.0f)
{
a1.ElapsedTime = t;
a2.ElapsedTime = 10.0f - t;
t += Time.deltaTime * 0.3f;
yield return null;
}
}
}
Here Spline container is child of the parent and both spline animate has this single container attached.
It works properly for the first animate component but it shows some wired glitch for second one like this :

Is there any way to make it work properly?