Unity Animation playing twice

I am trying to play a simple animation attached to the camera in the FPS player.
And the problem is that the animation place twice without wait or anything like the player turnaround then turns back and turns around again then stops.

9735-1am.jpg

The script I am using is from outside and is as follows :

void Update(){
if(lit_1 == 1)
		{
			StartCoroutine(waitandturn());
		}
}
IEnumerator waitandturn()
	{
		yield return new WaitForSeconds(3);
		footsteps1 playastep = player_controller.GetComponent<footsteps1>();
		playastep.isOnF = false; // Also I have a problem here.
		camm.animation.Play("camera_turnaround");// the camera
		yield return new WaitForSeconds(camm.animation["camera_turnaround"].length);
		lit_1 = 2;
	}

and I also have a footsteps script I am trying to stop it using the same code as above and its not working, I would like anyone could also tell me how to stop a sound.
here is the script

1 Answer

1

Maybe you trigger animation twice. Did you try this?
if(!camm.animation.isAnimationPlaying)
{
camm.animation.Play(“camera_turnaround”);
}
Also you should check if you set lit_1=1 somewhere else