Z
Z
Zefirot2021-07-03 18:57:39
Unity
Zefirot, 2021-07-03 18:57:39

Is there any difference where to move the object?

So it became such a seemingly simple question, but still.
There is a control script, everything is calculated in it, especially which object (prefab) should move when and where, is there any difference to do the move in the same script

void Update(){
  if(Cells.Count > 0){
    foreach(KeyValuePair<string, ObjectCell> kv in Cells){
      if(Vector3.Distance(..................) > 0.01f){
        kv.Value.transform.position = Vector3.MoveTowards(.......);
        }
      }
    }

Or is it better to give the coordinates of the target to the prefab and he will move towards the target according to his update?
What is the best and correct way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-07-03
@GavriKos

The difference is that you don't know the order in which updates are called.
Those. in this case, as in your code, the positions will change exactly in the order in which the elements are located in the list.
And if you pass coordinates to them and they themselves will move in updates, then the sequence within the frame is not defined.
This does not mean that it is bad or good - this is a fact that simply needs to be taken into account.
Other than that, it's just a matter of architecture.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question