Function structure question: static functions and smooth movement

Hi,

I’m just starting to code in Unity, so I’ll really appreciate your help with a code structure problem I have:

  • I have several objects, each with its own code, and they need to call the same ‘general’ functions, so I made these static.

  • The objects need to be moved (very simple x,z translation through a square grid). I want the movement to be smooth. The movement triggers when some of the conditions worked in the static functions come to be true.
    If I understood correctly, there are 2 way to generate such type of movement:

  • using the Update() function

  • using coroutines

  • If I use the Update function to generate the smooth movement, I cannot control the flow of events, and when exactly do the animation happen in relation to when the object is destroyed, for instance.

  • I cannot use coroutines to control the flow of events and the animations, since yield statments are not allowed in static functions.

So my question is:

  • how can I make a smooth movement of an object when some conditions are met inside a static function?
  • is there a way or some piece of advice to follow when using the Update function to better control the flow of events?

Thanks!

I’d recommend using coroutines, and not static functions, but rather a singleton. For example, MoveObject.

–Eric

Thanks, Eric, for the quick answer…the link is not available as of now, ‘technical difficulties, return later’, but as soon as I can I’ll have a look at it.