I’m even more confused because the error says it is on line 67, but your script doesn’t have that line (and looks like tyou have not included the whole script because there are no “using” lines in it).
Please post your full script.
But based on your indication of “error line” have you assigned all of the items you have as SerializeField (like mSource)? You say that you have assigned the slider, but have you assigned the AudioSource?
You probably have an extra component somewhere in the scene. Use the second overload of Debug.Log to highlight the component when you select the log entry.
Sounds like some of your code is referencing/calling methods on the prefab itself, and not the instance in a scene. The prefab in your project files is not the same as an instance in a scene. You will want to make sure your code is acting on the instance, and not the asset.
Prefabs are basically pre-made objects you can cut and paste throughout your scene. However, each copy you make is separate at runtime and have no connection to one another.
With prefabs you generally want your code to act on the instances in the scene. So if you want to reference it via the inspector, for example, drag in the instance from the scene, not the asset in your project folders. That’s the best I can describe ‘how’ to do it.
thank you so much!!! it’s working now!! : D
but the other music (or other background music) are not playing. I have different music for some scenes and idk why it’s not working now…
here’s my code for it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;
public class Soundmanager : MonoBehaviour
{
public static Soundmanager Instance;
public Sound[] musicSounds, sfxSounds;
[SerializeField]
public AudioSource mSource, sfxSource;
[SerializeField]
public Slider musicSlider;
[SerializeField]
public Slider sfxSlider;
public void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
return;
}
if (SceneManager.GetActiveScene().buildIndex == 0)
{
PlayMusic("Main");
Debug.Log("playing main");
}
else if (SceneManager.GetActiveScene().buildIndex == 1)
{
StopMusic("Main");
PlayMusic("Intro");
Debug.Log("playing intro");
}
else if (SceneManager.GetActiveScene().buildIndex == 2)
{
StopMusic("Intro");
PlayMusic("Quiz");
Debug.Log("playing quiz");
}
else if (SceneManager.GetActiveScene().buildIndex == 6)
{
StopMusic("Quiz");
PlayMusic("Results");
Debug.Log("playing results");
}
}
edit: nvm!! i kinda fixed it by putting the play music code on my scene switcher instead. thank you anyway!! : D