Skip to content

Instantly share code, notes, and snippets.

@thomprycejones
Created September 29, 2017 18:14
Show Gist options
  • Save thomprycejones/66aed202cd0a7bbcd16a89248b9eef58 to your computer and use it in GitHub Desktop.
Save thomprycejones/66aed202cd0a7bbcd16a89248b9eef58 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.SceneManagement;
public class MenuPrincipal : MonoBehaviour
{
// []:mundo {}:nivel ():nivel enumeracion completa
private Slider musicaSlider;
private Slider SFXSlider;
private AudioSource musica;
private SpriteRenderer negMusica;
private SpriteRenderer negSFX;
public GameObject creditos;
public Color fondoNormal;
public Color fondoMundo1;
public Color fondoMundo2;
public Color fondoMundo3;
public Color fondoMundo4;
public Color fondoMundo5;
public Image fondo;
public GameObject disabledMusicImage;
public GameObject disabledSFXImage;
private bool checkedMusic = false;
// Use this for initialization
void Start()
{
if (PlayerPrefs.GetInt("GG") == 1)
{
GameObject.Find("Principal").SetActive(false);
creditos.SetActive(true);
PlayerPrefs.SetInt("GG", 0);
}
}
// Update is called once per frame
void Update()
{
if (!checkedMusic)
{
try
{
checkSounds();
musica = Musica.GetMusica().GetComponent<AudioSource>();
musica.volume = PlayerPrefs.GetFloat("VolumenMusica");
//musica.Play();
}
catch (Exception)
{
}
checkedMusic = true;
}
}
public void FirstTimePlay() //Se encarga de empezar en el primer nivel para un noob
{
//string IsPlayerNew = PlayerPrefs.GetString ("IsPlayerNew");
//if (IsPlayerNew == "true")
//{
// LoadScene ("Level [1] {1} (1)");
// PlayerPrefs.SetString("IsPlayerNew","false");
//}
}
public void LoadLevel() //Carga nivel input
{
Debug.Log(transform.name);
}
public void LoadScene(string input) // carga un scene
{
SceneManager.LoadScene(input);
}
public void QuitGame() { Application.Quit(); } //Salir del juego
public void ResetPlayer()
{
PlayerPrefs.DeleteAll();
} //Reset de playerprefs
private string getBetween(string strSource, string strStart, string strEnd) //Ohhh, si...
{
int Start, End;
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
else
{
return "";
}
}
public void changeColorFondo(string mundo)
{
switch (mundo)
{
//case "normal":
// fondo.color = fondoNormal;
// break;
//case "1":
// fondo.color = fondoMundo1;
// break;
//case "2":
// fondo.color = fondoMundo2;
// break;
//case "3":
// fondo.color = fondoMundo3;
// break;
//case "4":
// fondo.color = fondoMundo4;
// break;
//case "5":
// fondo.color = fondoMundo5;
// break;
//default:
// break;
}
}
public void adjustMusic()
{
string volumen = PlayerPrefs.GetString("musicaEnabled");
if (volumen == "false")
{
disabledMusicImage.SetActive(false);
PlayerPrefs.SetFloat("VolumenMusica", 1f);
PlayerPrefs.SetString("musicaEnabled", "true");
checkVolume();
}
if (volumen == "true")
{
disabledMusicImage.SetActive(true);
PlayerPrefs.SetFloat("VolumenMusica", 0f);
PlayerPrefs.SetString("musicaEnabled", "false");
checkVolume();
}
}
public void adjustSFX()
{
string volumen = PlayerPrefs.GetString("SFXEnabled");
if (volumen == "false")
{
disabledSFXImage.SetActive(false);
PlayerPrefs.SetFloat("VolumenSFX", 1f);
PlayerPrefs.SetString("SFXEnabled", "true");
checkVolume();
}
if (volumen == "true")
{
disabledSFXImage.SetActive(true);
PlayerPrefs.SetFloat("VolumenSFX", 0f);
PlayerPrefs.SetString("SFXEnabled", "false");
checkVolume();
}
}
public void checkSounds()
{
string volumenMusica = PlayerPrefs.GetString("musicaEnabled");
if (volumenMusica == "false")
{
disabledMusicImage.SetActive(true);
}
if (volumenMusica == "true")
{
disabledMusicImage.SetActive(false);
}
string volumenSFX = PlayerPrefs.GetString("SFXEnabled");
if (volumenSFX == "false")
{
disabledSFXImage.SetActive(true);
}
if (volumenSFX == "true")
{
disabledSFXImage.SetActive(false);
}
}
private void checkVolume()
{
musica.volume = PlayerPrefs.GetFloat("VolumenMusica");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment