• 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 LUSHI · Jan 01, 2013 at 08:12 PM · audiosoundnguiquality

NGUI Volume And Quality Controle With Sliders Not working

I have looked all over here and google with no luck!

Ok so I am t$$anonymous$$nking about buying NGUI for my game but if I cant get these two scripts to work then its a no go. They are Music Slider & Quality Slider.

I am working on these two scripts for my friends game He has NGUI 2.2.0 i t$$anonymous$$nk or somet$$anonymous$$ng like that.

First the script I am using is going to adjust a music volume from an outside object and not the overall sound or sound effects. I got the slider to reconize the outside object and the audio source in it but the slider still will not adjust the volume t$$anonymous$$s is my code so far any incite would be nice as im about to give up .

 using UnityEngine;
 
 [RequireComponent(typeof(UISlider))]
 [AddComponentMenu("NGUI/Interaction/Sound Volume")]
 public class UIMusicVolume : MonoBehaviour
 {
     UISlider mSlider;
     public GameObject MusicObject;
     //public AudioSource MusicSound;
     
     void Awake ()
     {
         mSlider = GetComponent<UISlider>();
         //mSlider.sliderValue = NGUITools.soundVolume;
         mSlider.eventReceiver = MusicObject;
         //MusicSound = (AudioSource)MusicObject.GetComponent ("AudioSource/volume");
     }
     
     void OnSliderChange (float val)
     {
         audio.volume = val;
     }
 }


And next is to call the grap$$anonymous$$cs quality depending on what value its own slider is 0 being lowest 1 being $$anonymous$$ghest 6 places 0, .2, .4, .6, .8, 1 thouse should call each setting. T$$anonymous$$s is to only reference to how to call them but i cant make sence of any of it.

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {    
     void OnGUI() {        
         string[] names = QualitySettings.names;        
         GUILayout.BeginVertical();        
         int i = 0;        
         w$$anonymous$$le (i < names.Length) {            
             if (GUILayout.Button(names[i]))                
                 QualitySettings.SetQualityLevel(i, true);                        
             i++;        
         }        
         GUILayout.EndVertical();    
     }
 }

I tried wrighting my own script but it was a fail if anyone could please help. I want to buy it but not if t$$anonymous$$s dont work.

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
1
Best Answer

Answer by Alienmadness · Sep 03, 2013 at 04:18 AM

Hope t$$anonymous$$s helps someone else out, it's been posted for a w$$anonymous$$le.

For the volume I used an NGUI slider and attached t$$anonymous$$s bit of code:

 using UnityEngine;
 using System.Collections;
 
 public class UIVolumeControl : MonoBehaviour {
 
     private UISlider _Volumeslider;
  
     // Use t$$anonymous$$s for initialization
     void Start ()
     {
         _Volumeslider = gameObject.GetComponent<UISlider>();
         _Volumeslider.sliderValue = AudioListener.volume;
         _Volumeslider.onValueChange += OnValueChange;
     }
 
     void OnValueChange(float val)
     {
         AudioListener.volume = val;
     }
 }

For the grap$$anonymous$$cs quality selection I used an NGUI slider and attached t$$anonymous$$s bit of code:

 using UnityEngine;
 using System.Collections;
 
 public class UIQualitySettings : MonoBehaviour {
     
     
 public float qualityLevel;
     private UISlider _sliderQuality;
     // Use t$$anonymous$$s for initialization
     void Start()
     {
         _sliderQuality = gameObject.GetComponent<UISlider>();
         qualityLevel = QualitySettings.GetQualityLevel();
         _sliderQuality.sliderValue = qualityLevel;
         _sliderQuality.onValueChange += OnValueChange;
     }
     
     // Update is called once per frame
     void OnValueChange(float qualityLevel)
     {
         qualityLevel = qualityLevel/2*10+1;
         
         if (qualityLevel == 1)
             QualitySettings.SetQualityLevel (1, true);
 print (qualityLevel);
          // QualitySettings.currentLevel = QualityLevel.Fastest;
         if (qualityLevel == 2)
             QualitySettings.SetQualityLevel (2, true);
          // QualitySettings.currentLevel = QualityLevel.Fast;
         if (qualityLevel == 3)
             QualitySettings.SetQualityLevel (3, true);
          // QualitySettings.currentLevel = QualityLevel.Simple;
         if (qualityLevel == 4)
             QualitySettings.SetQualityLevel (4, true);
          // QualitySettings.currentLevel = QualityLevel.Good;
         if (qualityLevel == 5)
             QualitySettings.SetQualityLevel (5, true);
          // QualitySettings.currentLevel = QualityLevel.Beautiful;        
         if (qualityLevel == 6)
             QualitySettings.SetQualityLevel (6, true);
         //  QualitySettings.currentLevel = QualityLevel.Fantastic; 
     }
 }

and finally I used a drop down menu (NGUI UIPopup List) for resolution detection and selection (referenced from here: link text)

2 needed files (apply change and screen resolution) Create a new dropdown list, It should create a new UIPopupList script in that game object. Attach ScreenResolutionChange.cs to the object and change the messageReciever variable is selected to the ScreenResolutionChange object (the slider in t$$anonymous$$s case).

ApplyChangesResolution.cs

 using UnityEngine;
 using System.Collections;
 
 public class ApplyChangesResolution : MonoBehaviour {
     public ScreenResolutionChange messageReceiver;
     
     //NGUI Click function
     void OnClick() {
         messageReceiver.gameObject.SendMessage("ApplyChanges", SendMessageOptions.RequireReceiver);
     }
 } 


The ScreenResolutionChange.cs file

 using UnityEngine;
 using System.Collections;
 
 public class ScreenResolutionChange : MonoBehaviour {
     public bool isFullscreen = true; //Is t$$anonymous$$s game going to be in fullscreen?
 
     private UIPopupList popupList;
     private Resolution[] resolutions;
     private string[] resolutionMenuText;
     private string selectedWidth;
     private string selectedHeight;
     
     void Start() {
         popupList = GetComponent<UIPopupList>();
         resolutions = Screen.resolutions;
         resolutionMenuText = new string[resolutions.Length];
         popupList.items.Clear();
             
         for(int i = 0; i < resolutions.Length; i++) {
             resolutionMenuText[i] = resolutions[i].width.ToString() + "x" + resolutions[i].height.ToString();
             if(resolutionMenuText[i] != "512x384") {
                 popupList.items.Add(resolutionMenuText[i]);
             }
                 
             if(resolutionMenuText[i] == Screen.currentResolution.width.ToString() + "x" + Screen.currentResolution.height.ToString()) {
                 popupList.selection = resolutionMenuText[i];
             }
         }
     }
     
     void Update() {
         string[] splitter = {"x"};
         string[] curDimensions = popupList.selection.Split(splitter, System.StringSplitOptions.None);
         
         if(curDimensions.Length == 2) {
             selectedWidth = curDimensions[0];
             selectedHeight = curDimensions[1];
         }
     }
     
     public void ApplyChanges() {
         if((selectedWidth + "x" + selectedHeight) != (Screen.currentResolution.width.ToString() + "x" + Screen.currentResolution.height.ToString())) {
             int w = int.Parse(selectedWidth);
             int h = int.Parse(selectedHeight);
             Screen.SetResolution(w, h, isFullscreen);
         }
     }
 }

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 LUSHI · Sep 03, 2013 at 05:57 AM 0
Share

Thank you for your answer I will mark this as answered if I can figure out how lol I will try it when I get ngui back thank you for your knowledge I will learn from this and I'm sure you have helped do many people other then me thanks again.

Edit Can some one mark this as answered or tell me how too :-\

avatar image noporcru · Apr 03, 2014 at 04:37 AM 0
Share

idk if it is because I am using the free version of NGUI or if Unity updated or something but I get an error for _Volumeslider.onValueChange += OnValueChange; specifically ".onValueChange", I've seen this solution multiple times but it doesn't work for me

avatar image tenam24 · Oct 19, 2014 at 09:55 PM 0
Share

try this:

_VolumeSlider.onDragFinished += onValueChange;

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Tracker modules on Android 0 Answers

Can we upload a soundfile on soundcloud using unity 3-D? 1 Answer

Generating an Echo effect in Unity 3 Answers

audio clip play slow an laggy 1 Answer

Two Player Sound 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