Sorry for bad English
So i wrote a script to create my games menu. The script is attached to my Main Camera(the cam is the audio source and listener too)Everything works fine exept two things.
**1.**I can’t hear the background music
**2.**If i click on “back” in the “Options” menu it creates a second cam and a third…etc.
I know why is this happening(i mean the 2.) but i can’t solve it.Only scene #0 has a Main Cam other scenes not(i have 3 scenes)
So here is the script:
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
public float sx_box; //Starting x point of the background box
public float sy_box; //Starting y point of the background box
public float ex_box; //Ending x point of the background box
public float ey_box; //Ending y point of the background box
public float sx1; //Starting x point of a button or slide
public float sy1; //Starting y point of a button or slide
public float ex1; //Ending x point of a button or slide
public float ey1; //Ending x point of a button or slide
public float sx2; //Starting x point of a button
public float sy2; //Starting y point of a button
public float ex2; //Ending x point of a button
public float ey2; //Ending y point of a button
int level; // Number of the current scene(0-Menu 1-Options 2-Game)
public float x; // The value of the volume
void OnGUI () {
DontDestroyOnLoad(transform.gameObject); //Keep the camera because i want the music to continoue after changing scenes
level = Application.loadedLevel;
audio.Play();
if (level == 0)
{
GUI.Box(new Rect(sx_box,sy_box,ex_box,ey_box), "ICT");
if(GUI.Button(new Rect(sx1,sy1,ex1,ey1), "Start")) {
Application.LoadLevel(2);
}
if(GUI.Button(new Rect(sx2,sy2,ex2,ey2), "Options")) {
Application.LoadLevel(1);
}
}
if (level == 1)
{
x = GUI.HorizontalSlider(new Rect(625, 90, 150, 20), x, 0.0F, 10.0F);
audio.volume = x;
if(GUI.Button(new Rect(sx2,sy2,ex2,ey2), "Back")) {
Application.LoadLevel(0);
}
}
}
}