• 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 /
  • Help Room /
avatar image
4
Question by creamywhite · Aug 06, 2016 at 06:29 AM · uibuttonbuttonsdisabledisabled

disable UI button

i want to disable a UI button once i already clicked it once, like in hangman game, how is that?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
26

Answer by Dustin_00 · Jun 10, 2020 at 02:04 AM

This leaves the button on the screen with the disabled color and the user can't click it:

 yourButton.interactable = false;

This leaves the button on the screen, the user can't click it, but does NOT use the disabled color:

 yourButton.enabled = false;

This removes the button from the UI entirely:

 yourButton.gameObject.SetActive(false);

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
15

Answer by Bladynator · Aug 06, 2016 at 08:47 AM

You might just want to make it non-interactable (then the button stays, but turn grey by default). You do this from your script by putting this in the script of the object where the button is located:

 GetComponent<Button>().interactable = false;
Comment
Add comment · Show 1 · 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 Vivien_Lynn · Aug 16, 2019 at 08:13 PM 3
Share

Don't forget to add using UnityEngine.UI; at the beginning

avatar image
1

Answer by mafanbong8819 · Feb 09, 2017 at 07:20 PM

try this script. is working.

video- disable button

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(Button))]
 public class disable : MonoBehaviour {
 
     //GUI btn = (GameObject)Instantiate(Resources.Load("MyButton"));
 
     //GameObject btn = GameObject.CreatePrimitive(PrimitiveType.Plane);
     //public Object btn = Object.Instantiate(Resources.Load("MyButton"));
     //public Color newColor;
     //public Button mybutton;
     //public Color newColor;
 
     public Sprite blockA;
     public Sprite blockA_disable;
     public bool condition;
     public Button mybutton;
     public int counter;
 
     void start()
     {
         mybutton = GetComponent<Button> ();
     }
 
     public void changebutton()
     {
         counter++;
         if (counter % 2 == 0) {
             mybutton.image.overrideSprite = blockA;
                  //condition for working button.
         } else {
             mybutton.image.overrideSprite = blockA_disable;
                  //condition for disable button
         }
 
     }
 
 }
 

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 R4y-GM · Nov 30, 2018 at 06:24 PM

very easy

 public gameobject yourbutton;
 public void DisableButton ()
 {
       yourbutton.setActive(false);
 }
 
 //you have to put this script function in onclick() of the button component

Comment
Add comment · Show 1 · 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 thegreatkoala · May 16, 2020 at 03:08 PM 2
Share

Except that DEACTIVATES the button, not DISABLES it

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

98 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How do I change a state in an FSM with an UI button? 0 Answers

Two buttons are staying in front of every other ui element regardless of where I put them in the hierarchy 1 Answer

How do I NOT play a sound on the first selected button. 2 Answers

World space canvas buttons are not working? 0 Answers

Button Flickering On and Off When Pressed 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