Hello All,
I am having a problem with sound in Unity - I always have. So hopefully this question will help clear them up once and for all.
I am using this script to play a sound for a dog caught in a trap - unfortunately I don’t have a closed trap model. Anyway when the game starts I am using this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class wolfSound : MonoBehaviour {
public AudioSource audio;
public AudioClip clip;
//is the wold still in the trap or free
bool isFree;
// Use this for initialization
void Start () {
isFree = false;
audio = GetComponent<AudioSource>();
if (!isFree){
print("not free");
audio.PlayOneShot(clip, .1f);
}
}
// Update is called once per frame
void Update () {
}//end update
}//end Class
Now this plays the sound at the beginning of the game, expectedly, so, except that in AudioSource component I have the Max Distance set for the sound at 15 metres and the 3rd person control is a lot further than that, so, it shouldn’t be heard. It is very loud and then when I do get within that 15 metre distance the sound can barely be heard. Also in the AudioSource component I have the sound looped - I realise this is probably the worst way to do it was the only way I could get the sound to function without sound contantly firing every game loop.
So I would be very appreciative if someone could tell me what I am doing wrong and anyway to rectify these problems.
Thankyou and Regards.