Getting slider values from a different scene (making sensitivity sliders and need help)

Updated 6 days ago in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on June 16, 2017

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):

  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityStandardAssets.CrossPlatformInput;
  5. namespace UnityStandardAssets.Characters.FirstPerson
  6. {
  7. [Serializable]
  8. public class MouseLook
  9. {
  10. public float XSensitivity;
  11. public float YSensitivity;
  12. public bool clampVerticalRotation = true;
  13. public float MinimumX = -90F;
  14. public float MaximumX = 90F;
  15. public bool smooth;
  16. public float smoothTime = 5f;
  17. public bool lockCursor = true;
  18. public Slider slider;
  19. public Slider slider1;
  20. private Quaternion m_CharacterTargetRot;
  21. private Quaternion m_CameraTargetRot;
  22. private bool m_cursorIsLocked = true;
  23. public MouseLook mouseLookCustom;
  24. public void sensValue()
  25. {
  26. XSensitivity = PlayerPrefs.GetFloat("OptionScore");
  27. YSensitivity = slider1.value = PlayerPrefs.GetFloat("OptionLives");
  28. }

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!

  1. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class sliderSaves : MonoBehaviour { public Slider XSlider;
  2. // Use this for initialization
  3. void Start()
  4. {
  5. XSlider.value = PlayerPrefs.GetFloat("OptionScore");
  6. }
  7. void Update()
  8. {
  9. PlayerPrefs.SetFloat("OptionScore", XSlider.value);
  10. }
  11. }
  • Liked by
Reply
2 7 days ago

When are you calling the sensValue method?

6 days ago

no where, hmmm should that be in the update?

6 days ago

I just need someone to help me re do this thing, I’ve been trying to figure out sensitivity sliders for months now and no luck… 

Show more replies
  • Liked by
Reply
Cancel