- Home /
Change the volume of the music menu
Hello, first of all sorry for my bad english ... Now, I'm recreating the Slender by a youtuber and the person who is creating not put music on the menu, I decided to get but when I go to Options and change the volume of the game nothing happens in the music menu, just change the rest sound. ..: s Can someone help me? Would be internally grateful ...
I'm not sure what you are asking. Posting the code you use to show the menu, attempt to change the volume and play the sound might help.
$$anonymous$$y problem is that I added a song to my menu, but when I go to the game options and methodological higher or lower the music that added nothing happened, only resulted in sounds that I had inserted into the game. Get it? : s
using UnityEngine; using System.Collections;
public enum $$anonymous$$enus{ $$anonymous$$ain$$anonymous$$enu, Options, Credits }
public class $$anonymous$$ain$$anonymous$$enuController : $$anonymous$$onoBehaviour {
public $$anonymous$$enus current$$anonymous$$enu = $$anonymous$$enus.$$anonymous$$ain$$anonymous$$enu; private float currentVolume = 1; private float currentSensibility = 10; public float maxSensibility = 16; public float $$anonymous$$Sensibility = 3; public string textCredits;
public GUISkin guiSkinToUse;
public Texture logoGame;
// Use this for initialization void Start () { if(PlayerPrefs.Has$$anonymous$$ey("CurrentVolume")){ currentVolume = PlayerPrefs.GetFloat("CurrentVolume"); } else{ PlayerPrefs.SetFloat("CurrentVolume", currentVolume); }
if(PlayerPrefs.Has$$anonymous$$ey("CurrentSensibility")){
currentSensibility = PlayerPrefs.GetFloat("CurrentSensibility");
}
else{
PlayerPrefs.SetFloat("CurrentSensibility", currentSensibility);
}
}
// Update is called once per frame void Update () {
}
void OnGUI(){ GUI.skin = guiSkinToUse; $$anonymous$$enusGame(); }
void $$anonymous$$enusGame(){
Vector2 sizeLogo = GetAbsolutePixels(new Vector2(60, 30));
GUI.DrawTexture(new Rect (Screen.width/2-sizeLogo.x/2, 60, sizeLogo.x, sizeLogo.y), logoGame);
switch(current$$anonymous$$enu){
case $$anonymous$$enus.$$anonymous$$ain$$anonymous$$enu:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
if(GUILayout.Button("Play")) Application.LoadLevel("GamePlay");
if(GUILayout.Button("Options")) current$$anonymous$$enu = $$anonymous$$enus.Options;
if(GUILayout.Button("Credits")) current$$anonymous$$enu = $$anonymous$$enus.Credits;
GUILayout.Space (10);
if(GUILayout.Button("Exit")) Application.Quit();
GUILayout.EndArea();
}break;
case $$anonymous$$enus.Options:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
GUILayout.Label("Options");
GUILayout.Space(3);
GUILayout.Label("Volume");
currentVolume = GUILayout.HorizontalSlider(currentVolume, 0, 1);
GUILayout.Label("$$anonymous$$ouse Sensibility");
currentSensibility = GUILayout.HorizontalSlider(currentSensibility, $$anonymous$$Sensibility, maxSensibility);
if(GUILayout.Button("Save")) SavePreferens();
GUILayout.Space(10);
if(GUILayout.Button("Back")) current$$anonymous$$enu = $$anonymous$$enus.$$anonymous$$ain$$anonymous$$enu;
GUILayout.EndArea();
}break;
case $$anonymous$$enus.Credits:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
GUILayout.TextArea(textCredits);
GUILayout.Space(10);
if(GUILayout.Button("Back")) current$$anonymous$$enu = $$anonymous$$enus.$$anonymous$$ain$$anonymous$$enu;
GUILayout.EndArea();
}break;
}
}
void SavePreferens(){ PlayerPrefs.SetFloat("CurrentVolume", currentVolume); PlayerPrefs.SetFloat("CurrentSensibility", currentSensibility); }
Vector2 GetAbsolutePixels(Vector2 pixels){ Vector2 pixelsAbsolute = Vector2.zero; pixelsAbsolute.x = pixels.x*Screen.width/100; pixelsAbsolute.y = pixels.y*Screen.width/100;
return pixelsAbsolute;
}
Answer by Rafael10 · Mar 16, 2014 at 05:48 PM
My problem is that I added a song to my menu, but when I go to the game options and methodological higher or lower the music that added nothing happened, only resulted in sounds that I had inserted into the game. Get it? : s
using UnityEngine; using System.Collections;
public enum Menus{ MainMenu, Options, Credits }
public class MainMenuController : MonoBehaviour {
public Menus currentMenu = Menus.MainMenu;
private float currentVolume = 1;
private float currentSensibility = 10;
public float maxSensibility = 16;
public float minSensibility = 3;
public string textCredits;
public GUISkin guiSkinToUse;
public Texture logoGame;
// Use this for initialization
void Start () {
if(PlayerPrefs.HasKey("CurrentVolume")){
currentVolume = PlayerPrefs.GetFloat("CurrentVolume");
}
else{
PlayerPrefs.SetFloat("CurrentVolume", currentVolume);
}
if(PlayerPrefs.HasKey("CurrentSensibility")){
currentSensibility = PlayerPrefs.GetFloat("CurrentSensibility");
}
else{
PlayerPrefs.SetFloat("CurrentSensibility", currentSensibility);
}
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
GUI.skin = guiSkinToUse;
MenusGame();
}
void MenusGame(){
Vector2 sizeLogo = GetAbsolutePixels(new Vector2(60, 30));
GUI.DrawTexture(new Rect (Screen.width/2-sizeLogo.x/2, 60, sizeLogo.x, sizeLogo.y), logoGame);
switch(currentMenu){
case Menus.MainMenu:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
if(GUILayout.Button("Play")) Application.LoadLevel("GamePlay");
if(GUILayout.Button("Options")) currentMenu = Menus.Options;
if(GUILayout.Button("Credits")) currentMenu = Menus.Credits;
GUILayout.Space (10);
if(GUILayout.Button("Exit")) Application.Quit();
GUILayout.EndArea();
}break;
case Menus.Options:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
GUILayout.Label("Options");
GUILayout.Space(3);
GUILayout.Label("Volume");
currentVolume = GUILayout.HorizontalSlider(currentVolume, 0, 1);
GUILayout.Label("Mouse Sensibility");
currentSensibility = GUILayout.HorizontalSlider(currentSensibility, minSensibility, maxSensibility);
if(GUILayout.Button("Save")) SavePreferens();
GUILayout.Space(10);
if(GUILayout.Button("Back")) currentMenu = Menus.MainMenu;
GUILayout.EndArea();
}break;
case Menus.Credits:{
//
GUILayout.BeginArea(new Rect(Screen.width/2-70, 400, 150, Screen.height));
GUILayout.TextArea(textCredits);
GUILayout.Space(10);
if(GUILayout.Button("Back")) currentMenu = Menus.MainMenu;
GUILayout.EndArea();
}break;
}
}
void SavePreferens(){
PlayerPrefs.SetFloat("CurrentVolume", currentVolume);
PlayerPrefs.SetFloat("CurrentSensibility", currentSensibility);
}
Vector2 GetAbsolutePixels(Vector2 pixels){
Vector2 pixelsAbsolute = Vector2.zero;
pixelsAbsolute.x = pixels.x*Screen.width/100;
pixelsAbsolute.y = pixels.y*Screen.width/100;
return pixelsAbsolute;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
spheres not colliding with world 1 Answer
I can't import anything in Unity!. 1 Answer
Need help with playing audio on click. 3 Answers
FPS Multiplayer Help 1 Answer