I have a series of objects that are moving in a direction with a given speed (children) and another object that changes the speed of these objects (controller).
If the controller adjusts the speed of all children part way through the children moving themselves, the spacing becomes uneven as some have been moved with the old speed and some have been moved with the new speed.
I have been able to solve this issue by using the Edit->Project Settings->Script Execution Order to make the controller execute before the children, but this doesn't seem ideal. Is there a better way to solve this problem?
Below are the very simple child and controller scripts.
// Child
public class MoveVertically
: MonoBehaviour
{
public float Speed;
void Update ()
{
transform.Translate (Vector3.down * Time.deltaTime * Speed);
}
}
// Controller
public class MoveChildrenVertically
: MonoBehaviour
{
public float Speed;
MoveVertically[] children;
void Start()
{
children = GetComponentsInChildren<MoveVertically> ();
}
void Update()
{
foreach (var symbol in symbols)
{
symbol.Speed = Speed;
}
}
}