• 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 siddharth3322 · Jan 21, 2014 at 07:12 AM · togglenguiunity4.3toggle button

Toggle Button for Sound On/Off

I am using NGUI for menu creation. For sound on/off purpose, I am using toggle button w$$anonymous$$ch works correctly.

So what next I have to do ? Also t$$anonymous$$s time I searched other posts for my current solution. If you more information then I am ready to provide.

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
3

Answer by Exalia · Jan 21, 2014 at 07:43 AM

You can make your code independent of previous button state

Example :

Button Script :

 public GameObject audioSource;
 bool soundToggle = true;
 
 OnGUI()
 {
  soundToggle = !soundToggle;
  if(soundToggle)
  {
   audioSource.SetActive(true);
   //audioSource.mute = true;
   //audioSource.volume = 1.0f;
  }
  else
  {
   audioSource.SetActive(false);
   //audioSource.mute = false;
   //audioSource.volume = 0.0f;
  }
 } 



When the button is pushed toggle a boolean, set the AudioListener in your scene to inactive when the boolean is false.

http://forum.unity3d.com/threads/74698-Toggle-Sound-On-Off

Comment
Add comment · Show 6 · 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 siddharth3322 · Jan 21, 2014 at 09:01 AM 0
Share

Thanks for you reply but at present I don't know how to get current state of the button? and How to use that state for enable / disable audio listener?

avatar image Exalia · Jan 21, 2014 at 09:14 AM 0
Share

Updated my answer

avatar image siddharth3322 · Jan 21, 2014 at 09:21 AM 0
Share

Basically you misunderstand my question. I already know core unity thing to perform this but I am first time using NGUI toggle button to implement same thing. So you have to help me in this.

avatar image Exalia · Jan 21, 2014 at 09:25 AM 0
Share

So your question is about NGUI specifically not Unity?

avatar image siddharth3322 · Jan 21, 2014 at 09:42 AM 0
Share

Sorry but my first line already state this thing

Show more comments

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

19 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

Related Questions

Setting Background using NGUI 0 Answers

Placing button at corner using NGUI 2 Answers

UI Toggle Component Broken? 0 Answers

Dynamic load and unload texture atlas 0 Answers

Angle Based on Terrain 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