Hi Peter,
It’s great to see that you are challenging yourself.
Does your timeline work? If so, that’s a fine solution. The only potential problem I see is the if-condition in the code which will have Unity execute the Play method each frame if the condition is true. I do not know if this restarts the animation.
If you are not happy with your current solution, you could use the Animator (instead of the Timeline) with the “Idle” and a new state, e.g. “Patrol”. You define a bool parameter and use it as the condition for the Idle → Patrol transition. And you enable “loop” in the animation. This way, you could simply set the bool to true in your code to have the animator change the state from “Idle” to “Patrol”.
If (Time.timeSinceLevelLoad > timeDelay) is your condition, maybe you could start a coroutine or the Invoke method in the Start method() instead of checking this condition each frame in the Update method. After x seconds, you could set the aforementioned bool to true to have the Animator run the “Patrol” state/animation.
If you have a more complex idea, you could define your rules in a coroutine, e.g. play the animation, pause, play the animation, pause. A coroutine allows you to implement delays.
Maybe you don’t even need any code. Check the transitions in the animator. Maybe it is possible to define that the idle state should be left after x seconds. In the transition settings, it is also possible to define how many times an animation is supposed to be played before the state gets exited.
The timeline is great if you want to synchronise multiple animation tracks, e.g. a player flying around in the world, then making enemies appear after x seconds and do things, etc.
The animator is great if you want to make things happen based on conditions, e.g. “if x happens, play this animation; if y happens, play that animation”.