Audio source error

I am trying to make a script that, when the main character controller enter the water it plays a sound file of someone swimming. I have the written the script (I’m not sure if it’s correct) and it says that it has an audio source error.

var SoundEffect : AudioClip ;

function Update () {
	var hit : ControllerColliderHit;
	if (hit.gameObject.tag == "Ocean") {
	audio.Play(SoundEffect);
	}
}


@script RequireComponent (AudioSource)

What did I do wrong?

I am fairly unexperienced with scripting before you state this…

Post the actual error message (that’ll make it easier to help).

It says “Assets/Scripts/SwimmingBehaviour.js(6,19): BCE0023: No appropriate version of ‘UnityEngine.AudioSource.Play’ for the argument list ‘(UnityEngine.AudioClip)’ was found.”

What do I do?

I’ve changed the code so it only sounds when the character moves.

The script is supposed to be so that when the character is touching the water, tagged “Ocean”, and the character moves, it makes a swimming sound. If you have a better script for this and don’t mind sharing then please let me know.

Regarding the error you’re getting, double check the documentation for the Play() function here, and then see the documentation for the AudioSource component for some alternatives you can use.