• 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
2
Question by NatalSJ · Feb 20, 2017 at 09:43 AM · ui3dplayerprefstoggleimage effects

Changing Toggle UI's value (Checked or Unchecked)

I can't seem to find a way wherein we can change the value of the Toggle UI.

Setting it to checked or unchecked. I wonder if it's really impossible or I'm just missing something.

Why I need it?: I'm developing a 3D Game where there are ImageEffects such as Bloom, Motion Blur, and Antialiasing. And I have a pause menu with settings that toggles those ImageEffects to turn it on or off.

Somehow, I wanted it to be saved in PlayerPrefs so once an ImageEffect is off, it will stay off once you open the game again.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by JaredHD · Feb 20, 2017 at 06:44 PM

You use .isOn to set the value. E.G

 using UnityEngine;
 using UnityEngine.UI;
 
 public class HelpSomeone : MonoBehaviour
 {
     GameObject inGameToggle;
 
     private void Start()
     {
         inGameToggle = GameObject.Find("Toggle Name");
     }
 
     //Use buttons linked to this
     public void ChangeValueToTrue()
     {
         inGameToggle.GetComponent<Toggle>().isOn = true;
     }
 
     //Use buttons linked to this
     public void ChangeValueToFalse()
     {
         inGameToggle.GetComponent<Toggle>().isOn = false;
     }
 
 }
Comment
Add comment · Show 2 · 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 NatalSJ · Feb 20, 2017 at 06:49 PM 0
Share

Ohhh! Why didn't I see that! This is perfect. Thank you! :)

avatar image JaredHD NatalSJ · Feb 20, 2017 at 06:58 PM 0
Share

Not a problem :p Good Luck

avatar image
4

Answer by Jan_Sch · Feb 21, 2017 at 09:48 AM

I think it's something like

 toggle.isOn = true
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
avatar image
0

Answer by suzit-punk · Feb 20, 2017 at 10:19 AM

yes, it is possible. use bool var for every image-effects so every time when open the game set-get player pref for image-effects.

Comment
Add comment · Show 2 · 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 NatalSJ · Feb 20, 2017 at 05:35 PM 0
Share

$$anonymous$$ay I know what's the syntax for changing the Toggle UI?

Fore example, I have a Toggle variable: $$anonymous$$otionBlurToggle.

Is there something like: $$anonymous$$otionBlurtoggle.checked = true;

avatar image Vivien_Lynn NatalSJ · Mar 08, 2020 at 04:55 PM 0
Share

I am not exactly sure what you are asking for, but I hope this answers your question:

 // This will show you the state of your toggle in the console
 bool toggleState;
 $$anonymous$$otionBlurtoggle.isOn = toggleState;
 Debug.Log(toggleState);
 
 
 // This will toggle your Button on and off
 $$anonymous$$otionBlurtoggle.isOn = !$$anonymous$$otionBlurtoggle.isOn
 // Simply put: Turn my Toggle-State into what it is not
 // So if on, turn it off. If off, turn it on


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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Unlockable Levels 3 Answers

Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer

How can I collect playerprefs values? 0 Answers

Is it possible to import iOS style toggle buttons to Unity? 0 Answers

How do I place a video "behind" objects in the scene so it appears behind them in-game, rather than getting in the way completely? 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