Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Elit3d · Jan 18, 2015 at 10:35 PM · c#scenetogglefovmain camera

Access FOV from another scene

I want to be able to change the FOV from another scene with the slider. Is this possible to do?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Simon-Larsen · Jan 18, 2015 at 11:13 PM

You could save a variable in your PlayerPrefs and load that value once your new scene loads. From your first scene you could save your value, doing something like this

 PlayerPrefs.SetFloat("FOV", valueToSave);

And then fetch it from your other scene, doing something like this

 PlayerPrefs.GetFloat("FOV", defaultValue);

This will load any float value saved with the key "FOV", however you should always fill in a default value. Just in case no value was ever saved.

Comment
Add comment · Show 3 · 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
avatar image Elit3d · Jan 19, 2015 at 12:02 AM 0
Share

How is this grabbing the FOV from Camera exactly?

avatar image DaDonik · Jan 19, 2015 at 12:08 AM 2
Share
 PlayerPrefs.SetFloat("FOV", Camera.main.fieldOfView);
 Camera.main.fieldOfView = PlayerPrefs.GetFloat("FOV", 60.0f);

60 is the default FOV used by Unity, so if you haven't saved the FOV yet, it will use 60.

avatar image Elit3d · Jan 20, 2015 at 04:07 PM 0
Share

having issues: the camera wont change fov. This is what I have:

     void Start(){
         //fov 
         Camera.main.fieldOfView = PlayerPrefs.GetFloat("FOV", 60.0f);
         FOV.value = Camera.main.fieldOfView;
     }
 
 
     void Update () {
         FOVTxt.text = "" + FOV.value;
     }
 
     public void FOVSlider(float fovSlider){
         Camera.main.fieldOfView = fovSlider;
         PlayerPrefs.SetFloat("FOV", Camera.main.fieldOfView);
         PlayerPrefs.Save();
     }
avatar image
0

Answer by rmccabe82 · Jan 19, 2015 at 07:45 AM

Another option would be to make the slider value change set the value of a static variable somewhere. This static value would then be accessible from any other script later.

Comment
Add comment · Show 4 · 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
avatar image Simon-Larsen · Jan 19, 2015 at 12:52 PM 0
Share

You won't be able to access this value across scenes, unless you perserve the gameobject. And if you do that, you'll save the components value anyways. You also won't be able to save the value between sessions.

avatar image rmccabe82 · Jan 19, 2015 at 08:49 PM 0
Share

Im pretty sure I've passed values from one scene to another using static variables.

If you setup a static object in one script and set its value in one scene, you can still access the set value it from another when it loads. Its static, it will remain for the lifespan of your game.

Something along the lines of this maybe?

 public class ScriptA : $$anonymous$$onoBehaviour {
 
     public void sliderChanged(float sliderVal)
     {
         Debug.Log(sliderVal);
         ScriptB.FovValue = sliderVal;
     }
 }
 
 public class ScriptB : $$anonymous$$onoBehaviour {
 
     public static float FovValue;
 
     void Start()
     {
         // When the screen loads, set the FOV to the value of the static variable.
         Camera.main.fieldOfView = ScriptB.FovValue;
     }
 }
avatar image Simon-Larsen · Jan 19, 2015 at 11:11 PM 0
Share

Ah yes, you're correct. Still won't save the value between sessions though.

avatar image rmccabe82 · Jan 20, 2015 at 06:10 PM 0
Share

True, but the question was how to modify an object in one scene using the value from another, not persistence when the game reloads ;-)

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

27 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Add GUI elements to Scene View? 3 Answers

Deactivate game modes until tutorial is finished? 1 Answer

Access loading screen scene components from Main Menu? 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