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 ![]()
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);
}
}