Animation and trigger question!

Hi all! Ok here’s my little problem :

I got a door with an animation on it (it’s only slide out of the way) and I got a swicth that when the mouse click on it by Raycasting it’s playing the animation of the door.

Problem is everytime I hit the swicth, it’s playing the animation again!

Is there a way just to say play this animation once or delete the animation after?? or something like that ?

Here’s the code :

public var door02:Transform;
//ACTIVATING SWICTH02
	if(Physics.Raycast(ray,hit,rayDist))
	{
		if(hit.transform.name == "swicth02")
		{
			Debug.Log("Swicth02 hit");
			door02.animation.Play();
		}
	}

Don’t worry the raycasting work well it’s only the animation that bother me!

Thank all!

Set the clip’s wrap mode to ‘ClampForever’. This make the animation play exactly once, and then remain at the last frame. If you want to make sure that the ‘animation.Play()’ bit only happens once, put a bool in your script which it checks before playing the animation, and then sets afterwards so that it can only play once.

if(!hasPlayed)
{
    door02.animation.Play();
    hasPlayed = true;
}

Thank! The clamp forever thing it’s was exactly what i needed!