animation length not equaling 1

Such a strange little error going on currently.

If I uncomment the line - Debug.Log (player.animation [“myCubeAnim”].length); - I get the value 1

However if I hide that and debug the normalised time of my animation I get a value like 0.976 , it actually differs which is strange.
I’m thinking it may have something to do with my ontriggerenter function?

On occasion it will hit 1 and debug my line, but it’s a very small chance of that happening.
My animation is exactly a second long, wrapped to once.

Any ideas?

using UnityEngine;
using System.Collections;

public class playAnim : MonoBehaviour {

	public GameObject player; 

		void OnTriggerEnter(Collider collider) {
			if ( == "myTrigger") {
	void Update() {
		Debug.Log (player.animation ["myCubeAnim"].normalizedTime);
		//Debug.Log (player.animation ["myCubeAnim"].length);
		if ((player.animation ["myCubeAnim"].normalizedTime) >= 1) { 
			Debug.Log ("Hit");

There is nothing wrong. Your problem is that animations are sampled each frame. The “0.976” was the last time it was sampled. The next frame the animation is already finished and stopped.

If you want the animation to run to the very last keyframe you might want to use “clampfroever” as wrapmode and check the normalized time yourself to stop the animation in order to play another one.

normalisedTime never reaches to 1. Use this:

if (player.animation ["myCubeAnim"].normalizedTime > 0.9f) { 
    Debug.Log ("Hit");

that’s working just fine for me…