- Home /
Problems with pulling a slider value - (Making sensitivity Sliders)
I'm just wondering why this doesnt work!? There arent any errors. I want to take the value (from my "menu" scene's slider, and use it's value to plug into as the float in the "MouseLook" Script. I saved my slider as a prefabs like I dragged it into the project area and then switched to my "game" scene and dragged it into the public Slider "slider" box in the inspector. I have a save script on my slider which saves its value, and if I run and reopen the game, the slider values are saved and remain how I set them. However, in my MouseLook script, the sider.value is not effecting the sensitivity! Here are my MouseLook Scirpt, and my slider save script, and it's important to note on the FPSController, the MouseLook script is accessed. If you have used the standard unity asset you would know what im talking about, there is a line of code in the FirstPersonController Scirpt that looks like this: `
[SerializeField] public MouseLook m_MouseLook;
My MouseLook Script(not all of the scirpt, just the top where I am working):
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Characters.FirstPerson
{
[Serializable]
public class MouseLook
{
public float XSensitivity;
public float YSensitivity;
public bool clampVerticalRotation = true;
public float MinimumX = -90F;
public float MaximumX = 90F;
public bool smooth;
public float smoothTime = 5f;
public bool lockCursor = true;
public Slider slider;
public Slider slider1;
private Quaternion m_CharacterTargetRot;
private Quaternion m_CameraTargetRot;
private bool m_cursorIsLocked = true;
public MouseLook mouseLookCustom;
public void sensValue()
{
XSensitivity = PlayerPrefs.GetFloat("OptionScore");
YSensitivity = slider1.value = PlayerPrefs.GetFloat("OptionLives");
}
And lastly, my script to save the values (it is on a seperate game object (empty) on the same scene as the slider ("menu") and has the script attached to it and in the public Slider XSlider area, the slider was dragged directly from the Hierarchy into the box. Thanks for any help!
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class sliderSaves : MonoBehaviour { public Slider XSlider;
// Use this for initialization
void Start()
{
XSlider.value = PlayerPrefs.GetFloat("OptionScore");
}
void Update()
{
PlayerPrefs.SetFloat("OptionScore", XSlider.value);
}
}
Your answer
Follow this Question
Related Questions
Getting a slider value from a different scene 1 Answer
Slider value saving? 1 Answer
Slider value not working? 0 Answers
Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer
Slider issues 1 Answer