I have this script for every time I click the left mouse button a sound is played. Everything works fine but I keep seeing an error pop up every time I click. The error states “ArgumentNullException: Value cannot be null” and I don’t know why this error keeps popping up
Here’s the code I’m using:
public class AudioPlay : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)) //Detects if Left Mouse Button is clicked
{
GetComponent<AudioSource>().Play();
}
}
}