How to play audio with C#

What i’m trying to do is make a theme play once i start the game, I’m trying to do this with code. I am also trying to make the music play through other scenes on the menu but the music to stop once entering the proper game. I have tried using:

AudioClip Main_theme;

void Start () 
{
  Main_theme = (AudioClip)Resources.Load ("Sound/Music/ Main Theme");

  Main_theme.Loop = true;
  Main_theme.Play();
}

After all this i was getting errors and i don’t know why.

Thank you for any help.

You don’t Play() an AudioClip. You Play() an AudioSource, which has a particular AudioClip loaded.

Assuming that the object on which this script is placed has an AudioSource component, try changing your code to:

void Start ()
{
  Main_theme = (AudioClip)Resources.Load ("Sound/Music/ Main Theme");
  audio.clip = Main_theme;
  audio.Loop = true;
  audio.Play();
}