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 MachCUBED · Jun 02, 2012 at 09:31 PM · guigameobjectngui

Problems using NGUI for in-game options sliders

Hi guys,

I have the following script on a GameObject named Menu Manager in my main menu scene:

var gameSceneName : String;

var sensitivitySlider : GameObject; var musicSlider : GameObject; var soundSlider : GameObject;

var sound : float; var music : float; var sensitivity : float;

function Start () { sound = 0; sound += PlayerPrefs.GetFloat("SoundVol");

 music = 0;
 music += PlayerPrefs.GetFloat("MusicVol");
 
 sensitivity = 0;
 sensitivity += PlayerPrefs.GetFloat("Sensitivity");

}

function Update () {

}

function PlayGame () { Application.LoadLevel(gameSceneName); }

function QuitGame () { Application.Quit(); }

function OnSensitivitySliderChange () { PlayerPrefs.SetFloat("Sensitivity", sensitivitySlider.sliderValue); Debug.Log( "Sensitivity Slider Changed" + PlayerPrefs.GetFloat("Sensitivity")); }

function OnSoundSliderChange () { PlayerPrefs.SetFloat("SoundVol", soundSlider.sliderValue); Debug.Log( "Sound Slider Changed" + PlayerPrefs.GetFloat("SoundVol")); }

function OnMusicSliderChange () { PlayerPrefs.SetFloat("MusicVol", musicSlider.sliderValue); Debug.Log( "Music Slider Changed" + PlayerPrefs.GetFloat("MusicVol")); }

The scene also has an options panel with three sliders on it. The three sliders in the script are set to the three sliders on my options panel. Also, the Event Receiver for each of the three sliders is Menu Manager. When I run the scene and pull up the options panel, moving the sliders throws this error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible) Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value) Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value) MenuManager.OnMusicSliderChange () (at Assets/Menus/MenuManager.js:54) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UISlider:Set(Single, Boolean) (at Assets/NGUI/Scripts/Interaction/UISlider.cs:293) UISlider:UpdateDrag() (at Assets/NGUI/Scripts/Interaction/UISlider.cs:212) UISlider:OnDragThumb(GameObject, Vector2) (at Assets/NGUI/Scripts/Interaction/UISlider.cs:161) UIEventListener:OnDrag(Vector2) (at Assets/NGUI/Scripts/Internal/UIEventListener.cs:41) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:837) UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:695) UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:576)

This happens for each and every slider. It says some object isn't set, but the receiver is set for the sliders, the relevant functions are set for each slider, and the sliders in Menu Manager are set. Even stranger is the fact I can'r subclass the sliders to NGUI's UISlider class. Does the script have to be rewritten in C# for it to work properly, or is something else wrong?

MachCUBED

Comment
Add comment · Show 4
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 Datael · Jun 03, 2012 at 01:42 AM 1
Share

The most immediate problem I can see here is that musicSlider is declared as a GameObject and you're trying to access its .sliderValue which I'm assu$$anonymous$$g is an NGUI thing? You might need a GetComponent, or NGUI might be sending you the object as part of a delegate call somewhere. You should probably see if it's doing that before you try a GetComponent. I'm surprised, though, that it's even compiling to be honest. (Oh, and check that you're assigning those musicSlider variables in the inspector properly, too!)

avatar image MachCUBED · Jun 03, 2012 at 06:13 PM 0
Share

I'm just going to ask them and post the link here when it's fixed.

avatar image MachCUBED · Jun 04, 2012 at 08:42 PM 0
Share

They say that it's awaiting approval, but here's the link anyway: http://www.tasharen.com/forum/index.php?topic=609.0 it turns out that the GameObjects need to be UISliders, but making them UISliders in Javascript causes compile time errors. $$anonymous$$aybe the script needs to be redone in C#.

FIXED: See above link for details, the script must be in C#.

avatar image cregox · May 14, 2013 at 07:57 PM 0
Share

@$$anonymous$$achCUBED Did you fix your issue there, chaging to C#? If so, you really should answer your own question and accept it! ;-)

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Unity3D Game Time 1 Answer

How to make a good options menu. 1 Answer

How to make text appear when moving next to an object? 3 Answers

GameObjects name As GuiText 2 Answers

create a GuiSkin 2 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