Hey, I’m trying to get an idea sorted out, and I was hoping the Unity community might be able to help.
I want to create a timeline class that keeps track of timelineEvents, much like how an animation keeps track of AnimationEvents. The trick is, I need it to work from directly inside a script, so I can’t merely rely on animations. In essence, it would have a duration, a current point, and timelineEvents set up along the length of it.
I’m trying to think of ways to keep track of these timelineEvents and trigger them as the current point goes past them, but everything I can think of is really, really messy. If anyone has any insight on this subject, I would greatly appreciate it.
You first want to group your timeline events like having an enum with motion, rotation, scale, change color / texture, play sound, whatever might be a possible change to track in your timeline. Then you can store such an enum within an array of its type on runtime. Thats how i would start with.
I would use a sorted dictionary, with the key as the “time to execute”. Your manager class should have a timer. Each frame you increment the timer. Pull all of the events off the start of the dictionary whose time has passed, and execute them.
Note you will have to reset the timer every two days or so to avoid floating point precision errors.