FPC collision sound

I’m trying to play a sound (named josh01Sound) when my FPC collides with an object with a (Josh01) tag, but I can’t get it to play.

Josh01 has a Box Collider and Rigid Body.
My FPC has a Character Controller.

I’ve added an audio source to the FPC
I’ve added the following code to the FPC

var josh01Sound : AudioClip;

function OnControllerColliderHit (Hit : ControllerColliderHit){
	
  if (gameObject.tag == "josh01") {
    audio.PlayOneShot (josh01Sound);

	}
}

@script RequireComponent (AudioSource)

Can someone please tell me where I’m going wrong or point me in the right direction.

Thanks.[/code]

hi,

change this

if (gameObject.tag == "josh01") {

to

if (__hit.__gameObject.tag == "josh01") {

Hi, thanks for prompt reply. I’ve made the change, but I’m now being told that for that line

expecting , found ‘hit’

you write Hit … so you can’t write hit in second time…
i mean your first character is capital , but next time you write it small.

Changed ‘hit’ to ‘Hit’ , but still getting error message:

Scripts/ReadingSoundScript.js(4,16): BCE0044: expecting ), found ‘Hit’.

change both to “hit”

Yes, I have done that, but still getting the same error:

Scripts/ReadingSoundScript.js(4,16): BCE0044: expecting ), found ‘hit’.

My script currently reads

var josh01Sound : AudioClip;

function OnControllerColliderHit (hit : ControllerColliderHit){
	if (__hit.__gameObject.tag == "josh01") {
	
	audio.PlayOneShot (josh01Sound);
	
	}
}

@script RequireComponent (AudioSource)

hi,
:sweat_smile: Sorry, in my first post there where a that you didn’t understand

 __hit__

is the problem that I put To for underline the word hit.here your code
```
__var josh01Sound : AudioClip;

function OnControllerColliderHit (hit : ControllerColliderHit){
if (hit.gameObject.tag == “josh01”) {

audio.PlayOneShot (josh01Sound);

}
}__
```
Sorry again :slight_smile:

No problem. I should have twigged that myself.

It’s the little things that trip me up!

Works a treat now.

Thanks once again.

:smile: