Question by
ayylmao12345 · Oct 25, 2015 at 12:31 AM ·
compilerplaymode
Error CS1519 when trying to run project?
I want my BGM not to reset every time the scene changes so I was using the C# code from this link:
http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html
But when I try to run the code I get "error CS1519: unexpected symbol ' (' in class, struct, or interface member declaration". I realize this is probably just a missing semicolon or something but I'd appreciate any help because I am thoroughly stuck.
using UnityEngine;
using System.Collections;
public class MyUnitySingleton : MonoBehaviour
{
public AudioSource musicSource;
private static MyUnitySingleton instance = null;
public static MyUnitySingleton Instance {
get { return instance; }
}
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
} else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
musicSource.Play ();
}
Comment
Answer by Statement · Oct 25, 2015 at 12:36 AM
You got a statement in the class body.
musicSource.Play ();
Put it in a function. Maybe Awake. I dont know what you want to do.
using UnityEngine;
using System.Collections;
public class MyUnitySingleton : MonoBehaviour
{
public AudioSource musicSource;
private static MyUnitySingleton instance = null;
public static MyUnitySingleton Instance { get { return instance; } }
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
} else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
musicSource.Play (); // Moved it here...
}
}