|
Hello everyone, I was wondering how to chain actions and preserve order using scripting one after the other. For example:
Now I don't want the details of transformation/audio-playing/animation, as I already know how to do each of them. However, I don't know how to timely and orderly chain them one after the other so that once the first one finish, the second one start, and once it has finished the third one start etc. Thanks
(comments are locked)
|
|
You can use a call back method when another action is done to tell you when to fire the next step in the sequence. You can do this all in one script using boolean flags or you can separate out each task into its own game object and then you can place any combination of tasks into a game object array where they can be triggered in the correct order. You can even queue up the same object more than once if you want repeated actions. e.g.
You initialise the sequence by calling TaskDone(0); If all the tasks were set as children of the game controller object you can simply use SendMessageUpwards to send the complete message to the controller. If one of the tasks were to play an audio it'd look like this: Hmmm... I think you overcomplicated things. I only wanted an easy way to do things in sequence. What you have done can be done using a while loop for each action where you check if the action finished or not instead of using multiple GameObjects and messaging. I was seeking for a way to do it without continous checking especially when I want to do lots of chained actions. I really appreciate your examples, but I will see if I can have a better solution.
Aug 21 '10 at 06:49 PM
airt
Lol, I designed the script to be hassle free and flexible and you wanted a while loop. The call back method is the best if you want asynchronous sequencing.
Aug 21 '10 at 09:48 PM
spinaljack
I've upvoted this because it's the answer I would be looking for. Cheers Spinaljack (and sorry airt!)
Aug 22 '10 at 12:04 AM
Marowi
(comments are locked)
|

Upvoted because I think this is a great question, but not certain of an answer. I'll have a think/experiment. I don't think Unity natively supports events/callbacks, or perhaps I just haven't come across them yet.
You are right, I am looking for something similar to callbacks/events. But I believe no such thing is possible currently, this is why I want to see what people might suggest instead.