For some reason my code is the exact same as ricks but an error shows up that says ‘MusicPlayer’ does not contain a definition for ‘Length’ and no accessible extension method ‘Length’ accepting a first argument of type ‘MusicPlayer’ could be found (are you missing a using directive or an assembly reference?) so i tried defining the Length as an int but now my game keeps playing the audio everytime you crash so that it layers. someone help
heres my code:
using UnityEngine;
public class MusicPlayer : MonoBehaviour
{
int Length;
void Awake()
{
int numMusicPlayers = FindObjectOfType().Length;
if(numMusicPlayers > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
}