Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ChompIV · Jun 15, 2017 at 10:41 PM · sceneplayerprefsfloatslidervalue

Getting a slider value from a different scene

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);
  }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Brogan89 · Jun 15, 2017 at 10:57 PM

You probably shouldn't use PlayerPrefs in update function. Also, I'm not 100% sure what you are meaning, but if you want to store and save values across scenes, it is best to use and static class or static variables.

I don't know enough about PlayerPrefs but I never use them, never found a need to. What i would do if I was you if make a class

  public static class SaveStuff
 {
     public static float optionScore;
 }

Then from any script you can use go:

 SaveStuff.optionScore = XSlider.value; // saving data
 XSlider.value = SaveStuff.optionScore; // load stuff
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with pulling a slider value - (Making sensitivity Sliders) 0 Answers

Slider value not working? 0 Answers

Slider value saving? 1 Answer

Slider issues 1 Answer

Slider.value won't change to INT 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges