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 Isaac2201 · Mar 30 at 01:29 AM · script.volume

Volume settings issues

Here is the error that I ran into Assets\Scripts\OptionsScreen.cs(67,15): error CS0128: A local variable or function named 'vol' is already defined in this scope

Here is a copy of the code

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 using UnityEngine.Audio;
 
 public class OptionsScreen : MonoBehaviour
 {
     public Toggle fullscreenTog, vsyncTog;
 
     public List<ResItem> resolutions = new List<ResItem>();
     private int selectedResolution;
 
     public TMP_Text resolutionLabel;
 
     public AudioMixer theMixer;
 
     public TMP_Text mastLabel, musicLabel, sfxLabel;
 
     public Slider mastSlider, musicSlider, sfxSlider;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         fullscreenTog.isOn = Screen.fullScreen;
 
         if (QualitySettings.vSyncCount == 0)
         {
             vsyncTog.isOn = false;
         } else
         {
             vsyncTog.isOn = true;
         }
 
         bool foundRes = false;
         for(int i = 0; i < resolutions.Count; i++)
         {
             if(Screen.width == resolutions[i].horizontal && Screen.height == resolutions[i].vertical)
             {
                 foundRes = true;
 
                 selectedResolution = i;
 
                 UpdateResLabel();
             }
         }
 
         if(!foundRes)
         {
             ResItem newRes = new ResItem();
             newRes.horizontal = Screen.width;
             newRes.vertical = Screen.height;
 
             resolutions.Add(newRes);
             selectedResolution = resolutions.Count - 1;
 
             UpdateResLabel();
         }
 
         float  vol = 0f;
         theMixer.GetFloat("MasterVol", out vol);
         mastSlider.value = vol;
 
         float vol = 0f;
         theMixer.GetFloat("MusicVol", out vol);
         musicSlider.value = vol;
 
         float vol = 0f;
         theMixer.GetFloat("SFXVol", out vol);
         sfxSlider.value = vol;
 
         mastLabel.text = Mathf.RoundToInt(mastSlider.value + 80).ToString();
 
         musicLabel.text = Mathf.RoundToInt(musicSlider.value + 80).ToString();
 
         sfxLabel.text = Mathf.RoundToInt(sfxSlider.value + 80).ToString();
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     public void ResLeft()
     {
         selectedResolution--;
         if(selectedResolution < 0)
         {
             selectedResolution = 0;
         }
 
         UpdateResLabel();
     }
 
     public void ResRight()
     {
         selectedResolution++;
         if(selectedResolution > resolutions.Count - 1)
         {
             selectedResolution = resolutions.Count - 1;
         }
         UpdateResLabel();
     }
 
     public void UpdateResLabel()
     {
         resolutionLabel.text = resolutions[selectedResolution].horizontal.ToString() + "x" + resolutions[selectedResolution].vertical.ToString();
     }
 
     public void ApplyGraphics()
     {
         //Screen.fullScreen = fullscreenTog.isOn;
 
         if(vsyncTog.isOn)
         {
             QualitySettings.vSyncCount = 1;
         }
         else
         {
             QualitySettings.vSyncCount = 0;
         }
         Screen.SetResolution(resolutions[selectedResolution].horizontal, resolutions[selectedResolution].vertical, fullscreenTog.isOn);
     }
 
     public void SetMasterVol()
     {
         mastLabel.text = Mathf.RoundToInt(mastSlider.value + 80).ToString();
 
         theMixer.SetFloat("MasterVol", mastSlider.value);
 
         PlayerPrefs.SetFloat("MasterVol", mastSlider.value);
     }
 
     public void SetMusicVol()
     {
         musicLabel.text = Mathf.RoundToInt(musicSlider.value + 80).ToString();
 
         theMixer.SetFloat("MusicVol", musicSlider.value);
 
         PlayerPrefs.SetFloat("MusicVol", musicSlider.value);
     }
 
     public void SetSFXVol()
     {
         sfxLabel.text = Mathf.RoundToInt(sfxSlider.value + 80).ToString();
 
         theMixer.SetFloat("SFXVol", sfxSlider.value);
 
         PlayerPrefs.SetFloat("SFXVol", sfxSlider.value);
     }
 }
 
 [System.Serializable]
 public class ResItem
 {
     public int horizontal, vertical;
 }
 

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 rh_galaxy · Mar 30 at 03:31 AM

You are declaring vol 3 times, just remove line 67 and 71.

 float vol = 0f; //<- you can only declare this once and that is done on line 63
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

174 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 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 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

Can I attach AudioSource.PlayClipAtPoint to an Audio Mixer, so I can control the volume of these gameobjects? 0 Answers

How do I use the same script on enemy ai's and play animations in the animator controller properly on unity3d 0 Answers

How can i enable a Gameobject with an animation event? 1 Answer

How do i use StateMachine logic with my code ? 1 Answer

Why when using EditorWindow script type and MenuItem it's not add it to Hierarchy right click mouse context menu ? 0 Answers


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