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 xproject2013 · Sep 27, 2013 at 09:49 AM · buttonnguicheckbox

nGUI how to deactivate UICheckbox by script?

Hi, I'm new to nGUI (2.7), I'll explain shortly what I'm doing: I'm using a UIButton with UICheckbox script attached to make it stay selected when pressed. Another button has the duty to disable this button selected returning it to its initial state. In order to do this I created a script but the checkbox button doesn't return to its initial state (the checkmark sprite still active) despite the value isChecked it return false, can someone help me? Below you can see the script that I used, thanks in advance!

 public void checkboxInitialStyle (){
     UICheckbox checkbox = GameObject.Find("PressedButton").GetComponent<UICheckbox>();
     if (checkbox != null) {
         checkbox.isChecked = false;
     }
 }
Comment
Add comment · Show 1
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 Roothmans · Jun 21, 2014 at 09:17 PM 0
Share

You have to disable the checkmark sprite also ;) the checkbox can be disabled but having the mark still visible!

1 Reply

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

Answer by vexe · Oct 02, 2013 at 11:37 PM

Are you sure it's getting in and changing the value? How about you put a log to make sure it's getting in and that's checkbox isn't null:

  if (checkbox != null) {
     checkbox.isChecked = false;
     print ("I'm in");
 }

If it's not in, this means it's null so change the way you're getting the value of checkbox, why not just assign it from the inspector? It's better anyway than GameObject.Find

Else if it's in and it's still not changed, I suggest you debug, and follow the code inside NGUI and see how it behaves.

Comment
Add comment · Show 9 · 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 xproject2013 · Oct 03, 2013 at 08:12 AM 0
Share

Hi, i already check this and it works but the checkbox checkmark sprite still active. I update nGUI to 3.0.1 version so the code now is a little different:

 if (checkbox != null) {
     checkbox.value = false;
     Debug.Log("do it! " + checkbox.value);
 }
avatar image vexe · Oct 03, 2013 at 08:16 AM 1
Share

you're missing something, I can't tell. Did you try to follow execution inside NGUI's code to see what's it doing?

avatar image vexe · Oct 03, 2013 at 08:38 AM 1
Share

Did you assign the CheckSprite variable in your UICheckbox that's attached to your button?

avatar image vexe · Oct 03, 2013 at 09:05 AM 1
Share

For what exactly? - the CheckSprite is set via the inspector, or just myCb.checkSprite

avatar image vexe · Oct 03, 2013 at 09:12 AM 1
Share

I just created a button, attached a script to it that un-checks another checkbox, it worked (same code as yours). Can you tell me more about your setup?

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Unity 4.6 UI - Trigger OnClick event via script 1 Answer

GUI button to NGUI button ? 1 Answer

Script button. 1 Answer

Error wth enabling disabling scripts. 1 Answer

GUILayout to NGUI 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