AnimationState.time \ AnimationState.normalizedTime

What is the difference between AnimationState.time vs. AnimationState.normalizedTime?

The normalised time is the elapsed playback time divided by the length of the animation clip (so you are correct that 0 represents the start of the animation and 1 represents the end). However, if the clip is set to loop or repeat its last frame then the value can go above 1. You can think of this as a fraction or percentage of the length of the clip but this percentage can go above 100% if the animation plays for longer than its single play length.

https://forum.unity.com/threads/what-is-the-difference-between-animationstate-time-vs-animationstate-normalizedtime.86508/

 

====================================================================================

Get the current time of animation using script Unity3d

https://gamedev.stackexchange.com/questions/104662/get-the-current-time-of-animation-using-script-unity3d

Ask Question

Asked 4 years, 3 months ago

Active 4 years, 1 month ago

Viewed 5k times

1

I want to know the current time of the played animation using script in Unity3d. I tried using currentState.normalizedTime but this time is not the time of the animation, like it's the time of the runtime I think. Any advice please?

unity unityscript

shareimprove this question

asked Jul 27 '15 at 16:03

 

Tak

12822 silver badges1010 bronze badges

add a comment

2 Answers

active oldest votes

1

Try this:

    int frameNumber = Mathf.FloorToInt(normalizedtimeOfFrame* totalFrames);

shareimprove this answer

answered Jul 28 '15 at 19:08

 

Umair M

21611 silver badge1010 bronze badges

add a comment

1

You would use AnimationState.time

It can be larger than the length of the animation, so to get the value with this, you would need to modulo with the animation clip length.

float time = currentState.time % currentState.clip.length;

You can also use Normalized Time, but you would have to mulitply the value by the length instead of the animation (AnimationClip.Length)

float time = currentState.normalizedTime * currentState.clip.length;

shareimprove this answer

edited Jul 27 '15 at 16:45

answered Jul 27 '15 at 16:24

 

jgallant

7,70755 gold badges2626 silver badges4242 bronze badges

  • But this is the animation time or the run time? Like what if after running my application I didn't play the animation until 5 seconds, would these 5 seconds included when using AnimationState.Time? – Tak Jul 27 '15 at 16:26

  •  
  • Sorry, I was still editing the question after I posted it. – jgallant Jul 27 '15 at 16:28

  • I tried it and it gives this error Error CS0117: 'UnityEngine.Animation' does not contain a definition for 'length' (CS0117) (Assembly-CSharp) – Tak Jul 27 '15 at 16:43

  •  
  • You have to reference the actual animation instance. Use currentState.clip.length; – jgallant Jul 27 '15 at 16:44

  • it is still not working as it gives this error Error CS1061: 'UnityEngine.AnimatorStateInfo' does not contain a definition for 'time' and no extension method 'time' accepting a first argument of type 'UnityEngine.AnimatorStateInfo' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp) – Tak Jul 27 '15 at 16:47

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值