Is it possible to play animations while the TimeScale is 0? I’m talking about bone animations imported from Maya.
The basic scenario is that i have a bunch of rigidbodies on screen, i’d like to “pause” the screen on a button press, which plays an animation and turns timeScale to 0. But because timeScale is 0 animations won’t play at all.
Is there any way of achieving this?
I’ve got another method where i use delegates and events to notify objects when i’ve entered “pause mode”, but i thought that just turning the timeScale down would be more efficient than N method calls.
Thanks
//edit//
One idea that i do have is that i could write an extension for the AnimationClip class for a new function to play the animation, but also pass in a flag (ignoreTimeScale), if this flag is true, then i could scrub through the animation using a while(animation.time < animation.length). Or something like that. Thoughts?
That is indeed the newest way to make an animation without timescale, but his question was regarding Unity's old legacy animation system, which did not use the Animator component.
Yeah you sure can, just reverse your logic. So instead of setting the normalized time to the progress divided by the clip length, you want to set it to the normalized total (1) minus the difference. So that it starts from 1 and decreases. I edited my answer with the code.
I pretty much did it the way you said in your edit. Base it off the timed components from the animation, and create a coroutine that I kept track of in my own List and based other functions that coincided with it off of Time.realtimeSinceStartup. This was just a helper timer to base coroutines off of since coroutine yielding is also derived form timeScale.
Thanks for the confirmation! I'll implement this method now, and see how i go.
Might I ask how someone goes about creating a
“creating an animation extension function”? Does AnimationExtensions have to be its own public static class? Or is there another method to do this? Thanks.
Correct public static class AnimationExtensions { //Play an animation from a string parameter and run an oncomplete public static IEnumerator YourFunctionName( this Animation anim , string clipName, Action onComplete ) { } }
So I copied and pasted the c# script above and get these errors in the console. I never work with C# (only JS) and couldn’t work out what the problems are… can you help?
For the main script:
/AnimationExtensions.cs(1,28): error CS0116: A namespace can only contain types and namespace declarations
[is pointing to the following line in the script: public static IEnumerator Play( this Animation animation, string clipName, bool useTimeScale, Action onComplete ) ]
TYVM
As far as i know (Someone please correct me if im wrong) Actions only work in C#. So you cannot call them via javascript.
Action is part of the System.Action namespace in C#. Though I'm not familiar with JavaScript, Actions are part of the .Net library, so unless you can import it into JavaScript, I don't think you can use actions.
guys on the Action issue. it's easy enough to "get at" Action inside javascript, thank goodness. (if you use Prime31 plugins, you do it every day) Note my answer here, not the selected answer the "useful common trick" answer http://answers.unity3d.com/questions/443114/writing-with-c-and-javascript-simultaneoulsy.html essentially it's a delegate, like a Function type from U/S if you're struggling with the use of Action here, suggest very simply delete it from the proposed code, heh! hope it helps @Default117 your answer here is fantastic BTW, thanks!
That is indeed the newest way to make an animation without timescale, but his question was regarding Unity's old legacy animation system, which did not use the Animator component.
– Ben-BearFishI gave it +1 regardless if it answer the question, because it is useful to me and many others.
– green-coderbest answer
– mehdi14Best answer
– 1thewitcherthis is the best among the rest :D you helped me dude,
– tapang