Ok I have the animation stopping successful with the press of another key, however I wish to end the audio as well but I don’t want it destroyed as the player can listen back to it again if they wish. In a bit of a pickle at the moment here is the coding I have used, VoiceSound is where teh audio file is attached to.
function playTape()
{
{
AudioSource.PlayClipAtPoint(VoiceSound, transform.position);
TapeRecorder.GetComponent.<Animation>().Play();
}
}
function stopTape()
{
{
VoiceSound.AudioClip.Stop;
TapeRecorder.GetComponent.<Animation>().Stop();
}
}
You can’t stop an audio which is played with AudioSource.PlayClipAtPoint as, like you can read in the description of that function, it creates a temporary AudioSource instance which is automatically destroyed when the audio has finished playing. Since the method doesn’t return a reference to that instance you can’t stop it.
PlayClipAtPoint is a fire-and-forget method. If you want more control of an AudioSource you shouldn’t use this method. Create a gameobject, attach an AudioSource component and place it at the world position you like. That way you can play and stop an audio whenever you want.