Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 agepbiz · Aug 01, 2015 at 08:32 PM · playerprefssavetoggle

Save a Toggle Group state?

Unity 5, using the New UI

My android app is almost done, but I am seeking answer to a question that would make it much better. My programming/scripting skills are close to non existent, so bear with me. I have a dual controller setup (buttons and joysticks) which I can select via my settingspanel and a togglegroup

   ToggleGroupControls
     [x] ToggleJoysticks
     [ ] ToggleButtons

The toggles works by simply deactivating one controller and activating the other controller via GameObject.SetActive. This works perfectly, but the toggle selection resets itself when I restarts the app. So my question for you is; do any of you have a script that will save a toggle group state? I guess it will have to be done via PlayerPrefs? I have spent a couple of days and hours trying to search for an answer or a script that I can reverse engineer, but no luck so far, so I am close to giving up

Thanks

Comment
Add comment · Show 2
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 agepbiz · Aug 01, 2015 at 12:12 PM 0
Share

Thank you for the reply, but as said I have spent days googling and searching for something to build from, and I have been reading everything that I have come by so far. All the examples I have found have been for single toggle and usually not using the new UI. I find it incredibly hard to write the code from scratch, which most of us probably do in the beginning, since I am a non programmer. However I do have written a few scripts already but they all have been based on examples I have found, and I do learn a lot by doing so. babysteps. I come from a 3D designer background. I know it might be frustrating to get such noob questions, and believe me when I say that I hate asking for help, but I was only asking if someone had something similar already that they would love to share. This is not a crucial part of my app, since it is almost done, but it would make the user experience a bit better. Of course I will continue my search and read tutorials and hopefully this question will be approved by the moderator.

Thanks

avatar image agepbiz · Aug 01, 2015 at 07:30 PM 0
Share

I have finally solved it. This is the script I ended up with:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class SaveControllerSelection : $$anonymous$$onoBehaviour {
 
     public GameObject buttons;
 
     void Start()
     {
 
         int state = PlayerPrefs.GetInt("Controller", 0);
 
         if (state == 1)    
         {
             buttons.SetActive(true);
             transform.GetChild(1).GetComponent<Toggle>().isOn = true;
         }
     }
 
 
     public void SaveJoysticks()
         {
         PlayerPrefs.SetInt("Controller", 0);
         }
         
     public void SaveButtons()
         {
         PlayerPrefs.SetInt("Controller", 1);
         }
 
 
 }

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I save a three dimensional array? 1 Answer

How to save an Audio Mixer's value wich is adjusted with a Slider? 1 Answer

Save/load playerprefs 2 Answers

Problems with saving/loading score with PlayerPrefs [C#] 1 Answer

Saving Data! PLEASE HELP 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