Hi,
I’m simply trying to make an audio clip play on loop. I have the following code:
public AudioClip gallop;
AudioSource gallopSrc;
gallopSrc = new AudioSource();
gallopSrc.clip = gallop;
gallopSrc.loop = true;
gallopSrc.Play();
Also tried:
gallopSrc.PlayOneShot(gallop);
I always get the error NullReferenceException on the first line that mentions gallopSrc after the line gallopSrc = new AudioSource();. So it seems that gallopSrc is not being initialised.
I have assigned the correct audio clip to ‘gallop’ in the inspector. I have some other sound effects working by using the following code:
AudioSource.PlayClipAtPoint(gallop, Camera.main.transform.position);
However, this way doesn’t allow me to loop.