3.x Game Development Book Scripting Problem, -door does not play sound on collision-

I am new to Unity and trying to work through Will Goldstone’s book Unity 3.x Development Essentials. It has been a very informative book thus far and I have enjoyed the explanations and process.

However, I am stuck part way through chapter 5 while trying to get a playercollider set up to activate a door sound and animation when the FPC collides with the box collider assigned to a door object.

The setup is as follows:
on the door object I have a box collider and an audio source.

On the FPC I added the script below and assigned two audio files to the public variables for door open and close sound.

I get no errors when saving the script, only the following warning " CS0414: The private field ‘PlayerCollisions.doorTimer’ is assigned but its value is never used

Being totally new to scripting I can’t seem to find any errors , at least that I can recognize, in the script. I went through the setup explanations in the book several times and can’t seem to find anything that I missed or set up incorrectly either.

Obviously I am missing something however because when I walk up to the door while testing the game no sounds play.

Also the audio listener is on the FPC camera and I am hearing the ambient terrain sound looping w/o any issues.

Any advice would be greatly appreciated, I was really hoping to solve this on my own, but my hope is quickly waning :expressionless:

Thanks in advance!

PlayerCollisions script below that I am using:

using UnityEngine;
using System.Collections;

public class PlayerCollisions : MonoBehaviour {
bool doorIsOpen = false;
float doorTimer = 0.0f;
public float doorOpenTime = 3.0f;
public AudioClip doorOpenSound;
public AudioClip doorShutSound;

// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnControllerColliderhit(ControllerColliderHit hit) {
if(hit.gameObject.tag == “playerDoor” doorIsOpen == false) {
OpenDoor(hit.gameObject);
}
}
void OpenDoor(GameObject door) {
doorIsOpen = true;
door.audio.PlayOneShot(doorOpenSound);

}
}


Correct the casing of the H in OnControllerColliderhit so it says OnControllerColliderHit

Wow, …what an obvious mistake, I can’t believe I did not see that myself! I went over that script a dozen times looking for errors and never saw it!

Thanks for your help!

We’ve ALL done it before lol.

next time you’ve got a problem use the [/ CODE] much easier for people to help you :)