I have a Unity problem where I am trying to play sound when addScore() function starts using dingSFX.Play();, but instead I get the following error: ArgumentNullException: Value cannot be null.
I am using Audio Source component that I added into my Inspector tab where also my script(LogicScript.cs) is. I also added the AudioClip into Audio Source.
LogicScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LogicScript : MonoBehaviour
{
public int playerScore;
public Text scoreText;
public GameObject gameOverScreen;
public AudioSource dingSFX;
[ContextMenu("Increase Score")]
public void addScore(int scoreToAdd)
{
playerScore = playerScore + scoreToAdd;
scoreText.text = playerScore.ToString();
dingSFX.Play(); // this does not work
}
public void restartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void gameOver()
{
gameOverScreen.SetActive(true);
}
}