- Home /
public variable audio clip not initializing sound
using UnityEngine;
using System.Collections;
public class PlayerCollision : MonoBehaviour {
public bool doorIsOpen = false;
float doorTimer = 0.0f;
public float doorOpenTime = 3.0f;
public AudioClip doorOpenSound; //<--When game plays, this returns null
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){
//doorIsOpen = true;
OpenDoor(hit.gameObject);
}
}
void OpenDoor(GameObject door){
door.audio.PlayOneShot(doorOpenSound,1);
}
}
As you can see, I set the soundClip for the variable in the inspector but when the game plays and i run the debugger, it shows the the public variable is null. why is unity not setting my audio clip ??
I've had this happen when I have (mistakenly) had the same script attached to two game objects. Do a search in the Hierarchy view for your script name.
I searched my hierarchy view and my assets in my project manager. Its only attached to one object and thats the character controller. It seems like that wouldnt break it though. For example, what if I wanted to use multiple instances of the object on enemies etc.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Question on Vector3.Reflect() 2 Answers
What is the best way to script third person real-time action melee combat in C#? 1 Answer
C# Collision Detection Help 0 Answers
How to check if an object is colliding with another from another script ? 1 Answer