How to load an audiosource on trigger once?

Hey, I’m a sophomore in high school learning Unity and probably the hardest part is learning how to work with triggers in coding. So I’m using Unity’s Fps Controller and have some audio clips of me saying stuff that I want to activate when the player, tagged “Player” (if that matters), walks through a trigger, it would start the audio clip. I don’t know how to do this. I’ve tried doing
void OnTriggerEnter(Collider co)
{
{
GetComponent().Play();
}
} //the script is C#

but that didn’t work. Well it did, but I can trigger it multiple times which I DON’T want. I want it so that once you touch it, it plays the audioclip only ONE time. If you would know how to do this that would be great. Thanks and I’ll be clear as possible.

Is that how you’ve written the code? play audioclip. "MeTalking" ?

That’s incorrect in syntax. Okay, so, I will make a few assumptions. You have this script, a collider and an audiosource on this same object. You have to get the audiosource component, and you can do that by saying AudioSource source = GetComponent<AudioSource>();. Once you have it, you do source.Play() and it should play the sound that you have assigned in the audiosource component.

If anything’s still confusing, ask away.

I figured it out. this is the script that I used with Unity 5.5. This script is with JavaScript and it works great with Unity’s FPS Controller. What you do have to remember when working with this script is that you attach it to the object that you want to play the sound and set it to trigger. There is this space in the inspector where you can insert your audio, but that will not work. You must add an audiosource that doesn’t play on awake (or it does, it’s up to you) and that’s pretty much it.

var Sound : AudioClip;

private var hasPlayed = false;

function OnTriggerEnter(){
if(!hasPlayed){
audio.PlayOneShot(Sound);
hasPlayed = true;
}
}
{
GetComponent().Play();
}
}
}

You attach the script to the object that is set as a trigger and attach an audiosource to the object. In the audiosource you put the audio clip that you want it to play when it’s triggered. That script is tested and works.