- Home /
Question by
snon200 · Apr 18, 2016 at 03:09 PM ·
unity 5guisliderfield of view
cant slide GUI slider
hi, i have the following script for my pause menu and in this script i wanted to create a slider that will be able to change my field of view, any time the fov changes the slider moves to the right place but i cant move it to change the value, it only displays it, can anyone help me? thanks.
var mainMenuSceneName : String;
var pauseMenuFont : Font;
var pauseEnabled = false;
var FOV = Camera.main.fieldOfView;
function Start(){
pauseEnabled = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Cursor.visible = false;
}
function Update(){
if(Input.GetKeyDown("escape")){
if(pauseEnabled == true){
pauseEnabled = false;
Time.timeScale = 1;
AudioListener.volume = 1;
Cursor.visible = false;
}
else if(pauseEnabled == false){
pauseEnabled = true;
AudioListener.volume = 0;
Time.timeScale = 0;
Cursor.visible = true;
}
}
}
private var showGraphicsDropDown = false;
private var showFovDropDown = false;
function OnGUI(){
GUI.skin.box.font = pauseMenuFont;
GUI.skin.button.font = pauseMenuFont;
if(pauseEnabled == true){
GUI.Box(Rect(Screen.width /2 - 100,Screen.height /2 - 150,250,250), "Pause Menu");
if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,50), "Main Menu (will not save)")){
Application.LoadLevel(mainMenuSceneName);
}
if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 - 50,250,50), "Change Graphics Quality")){
if(showGraphicsDropDown == false){
showFovDropDown = false;
showGraphicsDropDown = true;
}
else{
showGraphicsDropDown = false;
}
}
if(showGraphicsDropDown == true){
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 - 50,250,50), "Fastest")){
QualitySettings.currentLevel = QualityLevel.Fastest;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 ,250,50), "Fast")){
QualitySettings.currentLevel = QualityLevel.Fast;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 50,250,50), "Simple")){
QualitySettings.currentLevel = QualityLevel.Simple;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 100,250,50), "Good")){
QualitySettings.currentLevel = QualityLevel.Good;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 150,250,50), "Beautiful")){
QualitySettings.currentLevel = QualityLevel.Beautiful;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 200,250,50), "Fantastic")){
QualitySettings.currentLevel = QualityLevel.Fantastic;
}
if(Input.GetKeyDown("escape")){
showGraphicsDropDown = false;
}
}
if (GUI.Button (Rect (Screen.width /2 - 100,Screen.height /2 + 50,250,50), "Quit Game (will not save)")){
Application.Quit();
}
if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 ,250,50), "Change FOV")){
if(showFovDropDown == false){
showGraphicsDropDown = false;
showFovDropDown = true;
}
else{
showFovDropDown = false;
}
}
if(showFovDropDown == true){
FOV = GUI.HorizontalSlider(Rect(Screen.width /2 + 150,Screen.height /2 - 50,250,50), Camera.main.fieldOfView, 40, 90);
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 ,250,50), "40")){
Camera.main.fieldOfView = 40;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 50,250,50), "50")){
Camera.main.fieldOfView = 50;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 100,250,50), "60 (default)")){
Camera.main.fieldOfView = 59;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 150,250,50), "70")){
Camera.main.fieldOfView = 70;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 200,250,50), "80")){
Camera.main.fieldOfView = 80;
}
if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 250,250,50), "90")){
Camera.main.fieldOfView = 90;
}
if(Input.GetKeyDown("escape")){
showFovDropDown = false;
}
}
}
}
Comment