I have a strange problem in unity3d. I want to use several audio sources for playing a sound with a overlapping effect. Because I can't explain the problem myself- I tried the same with only one AudioSource. So I have this script:
public class audioOverlap:MonoBehaviour
{
private AudioSource sct;
public AudioClip clp;
void Start(){
sct=new AudioSource();
sct.clip=clp;//NullReferenceException!?
}
}
Because of the NullReferenceException- I tried figuring out why.
void Start(){
sct=new AudioSource();
if(sct==null){Debug.Log("AudioSourceBug");/*gets executed-wtf???*/}
if(clp==null){Debug.Log("AudioClipBug");/*gets notexecuted-okay*/}
sct.clip=clp;//NullReferenceException!?
}
I know what a NullReferenceException is-please don't mark it as duplicate when the linked question isn't a working solution:
I'm a beginner with Unity, but not with C#.