Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using UnityEngine;
- public class OptionsController : MonoBehaviour {
- public Slider volumeSlider;
- public Slider difficultySlider;
- public Slider controlSlider;
- private float percentage;
- private int maxValue; //max types, if gamepad not detected max is 1 not 2
- public Text percentText;
- public Text difficultyLevel;
- public Text controlText;
- public Text ControlLeft;
- public Text ControlRight;
- private Color inactive = Color.gray;
- private Color active = Color.white;
- public LevelManager levelManager;
- private MusicPlayer musicManager;
- private GamePadManager gamePad;
- // Use this for initialization
- void Start()
- {
- levelManager = GameObject.FindObjectOfType<LevelManager>();
- musicManager = GameObject.FindObjectOfType<MusicPlayer>();
- gamePad = FindObjectOfType<GamePadManager>();
- volumeSlider.value = PlayerPrefsManager.GetMasterVolume();
- difficultySlider.value = PlayerPrefsManager.GetDifficulty();
- controlSlider.value = PlayerPrefsManager.GetControlType();
- }
- // Update is called once per frame
- void Update()
- {
- //if(gamePad.noGamepad)
- //{
- // controlSlider.maxValue = 1;
- //}
- //else
- //{
- // controlSlider.maxValue = 2;
- //}
- //Is a gamepad detected?
- if(gamePad.noGamepad)
- {
- maxValue = 1;
- }
- else { maxValue = 2; }
- // Activate or Inactivate Arrow
- if (gamePad.controlType == 0)
- {
- ControlLeft.color = inactive;
- }
- else if (gamePad.controlType > 0)
- {
- ControlLeft.color = active;
- }
- if (gamePad.controlType == maxValue)
- {
- ControlRight.color = inactive;
- }
- else if (gamePad.controlType < maxValue)
- {
- ControlRight.color = active;
- }
- percentage = Mathf.RoundToInt((volumeSlider.value / 1f) * 100);
- percentText.text = percentage + "%";
- CheckDifficulty();
- CheckControlType();
- //PlayerPrefsManager.SetMasterVolume (volumeSlider.value);
- musicManager.ChangeVolume(volumeSlider.value);
- if (musicManager == null)
- {
- return;
- }
- }
- void CheckDifficulty()
- {
- if (difficultySlider.value == 1)
- {
- difficultyLevel.color = Color.white;
- difficultyLevel.text = "Easy";
- }
- else if (difficultySlider.value == 2)
- {
- difficultyLevel.color = Color.white;
- difficultyLevel.text = "Normal";
- }
- else if (difficultySlider.value == 3)
- {
- difficultyLevel.color = Color.white;
- difficultyLevel.text = "Hard";
- }
- else if (difficultySlider.value == 4)
- {
- difficultyLevel.color = Color.red;
- difficultyLevel.text = "Masochist";
- }
- }
- void CheckControlType()
- {
- if (gamePad.controlType == 0)
- {
- controlText.text = "Mouse";
- }
- else if (gamePad.controlType == 1)
- {
- controlText.text = "keyboard";
- }
- else if (gamePad.controlType == 2)
- {
- controlText.text = "GamePad";
- }
- }
- public void ControlLeftArrow()
- {
- if (gamePad.controlType > 0)
- {
- gamePad.controlType--;
- }
- }
- public void ControlRightArrow()
- {
- if (!gamePad.noGamepad && gamePad.controlType < 2)
- {
- gamePad.controlType++;
- }
- else if (gamePad.noGamepad && gamePad.controlType < 1)
- {
- gamePad.controlType++;
- }
- }
- public void SaveAndExit()
- {
- PlayerPrefsManager.SetMasterVolume(volumeSlider.value);
- PlayerPrefsManager.SetDifficulty(difficultySlider.value);
- PlayerPrefsManager.SetControlType(gamePad.controlType);
- levelManager.Loadlevel("01a Start");
- }
- public void SetDefaults()
- {
- volumeSlider.value = 0.8f;
- difficultySlider.value = 2f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement