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
1
Question by mazket · Dec 05, 2014 at 11:46 AM · c#button

NEW GUI - Button - set interactable via script

I'm trying to recreate the cool down of a button after been used, so I have a timer and all but my problem is that when I try this:

 used.GetComponent<Button> ().interactable = true;

it doesn't recognize the variable/bool interactable and yes I'm using Unity Engine.UI at top, and when I try to type it, those are my options:

alt text

does is called something else or what should it be??

screenshot.jpg (189.1 kB)
Comment
Add comment · Show 5
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 mazket · Dec 05, 2014 at 07:30 AM 0
Share

forgot to tell if really matters, also try Gameobject used ins$$anonymous$$d of Transform

avatar image troien · Dec 05, 2014 at 12:09 PM 1
Share

As far as I know the thing you tried...

 used.GetComponent<Button>().interactable = true;

Is the correct code.

If you try this, does it compile? (Do you get an error in the console log in Unity that persists after you clear it?)

If you don't get an error, your problem is that for some reason your autocomplete isn't working, did you try restarting $$anonymous$$onoDevelop/visual studio? :D

avatar image mazket · Dec 05, 2014 at 09:53 PM 1
Share

yes I got an error in the unity console it says:

"Type Button does not contain a definition for 'Interactable' and no extension method 'Interactable' 'Button' could be found"

avatar image CanisLupus · Dec 05, 2014 at 10:53 PM 1
Share

See if you have another class named "Button" in your project. Probably also a $$anonymous$$onoBehaviour, or your GetComponent would give you errors first. When you're sure that a class contains a certain method or property, and the compiler says it doesn't, often it's because the compiler is seeing another class with the same name and trying to use that one.

avatar image CanisLupus · Dec 05, 2014 at 10:55 PM 0
Share

Also, the variable in question is called "interactable" (no capital letter) and not "Interactable", so that error the compiler gave you is actually correct :)

6 Replies

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

Answer by mazket · Dec 06, 2014 at 06:35 AM

CanisLupus was rigth on the money for some reason I create a script called button and that was where the getComponent was looking for and couldn't find interactable, delete it and worked, Thanks for the comments and answer!!

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
1

Answer by Kiwasi · Dec 06, 2014 at 12:52 AM

Sounds like its a conflict. Button.interactable is the correct member to access. Several users have reported conflicts with some plugins.

Two options to resolve.

  1. Find the conflict and rename the class. Right click on Button in your code editor. Go to "Find Declaration".

  2. Use the fully qualified name. As in

    GetComponent()

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 AlvinHerawan · Jan 13, 2015 at 06:52 PM 0
Share

Just to confirm the other readers. I still had errors using GetComponent().interactable but Bored$$anonymous$$ormon's suggestion of using GetComponent() works.

avatar image
1

Answer by jchart7 · Nov 02, 2015 at 02:46 PM

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI; // required when using UI elements in scripts
 
 public class Example : MonoBehaviour {
 
     public Button startButton;
     public bool playersReady;
 
 
     void Update () 
     {
         // checks if the players are ready and if the start button is useable
         if (playersReady == true && startButton.interactable == false) 
         {
             //allows the start button to be used
             startButton.interactable = true;
         }
     }
 }

  1. Make sure your have using UnityEngine.UI;

  2. Then set your variable public Button startButton;

  3. Finally call the action startButton.interactable = true;

TIP* NOT button.isInteractble

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
-1

Answer by M-G-Production · Dec 05, 2014 at 10:18 PM

Hi mazket!

Are you trying to acces a Script Component named "Button" or an GameObject?

If Button is an object:

 using UnityEngine;
 using System.Collections;
 
 public class Cooldown : MonoBehaviour {
 
     public GameObject used;
 
     // Use this for initialization
     void startCD () 
     {
         StartCoroutine (SkillCD ());
     }
     
     // Update is called once per frame
     IEnumerator SkillCD () 
     {
         yield return new WaitForSeconds(10f);
 
         used = GameObject.FindGameObjectWithTag ("Used");
         used.GetComponent<Button> ().interactable = true;
         used.tag = "Untagged";
     }
 }

QUESTION 1: Is "Button" an object or a script name? If it is an object, change the "Button" to the actual script name you are trying to access.

Is "interactable" a private bool? If it is private, it won't be accessible! Switch to public!

I think you are mixing some components...

Bests, Math!

Comment
Add comment · Show 3 · 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 mazket · Dec 05, 2014 at 10:44 PM 0
Share

well what I'm trying to access is the the script called button that is attached to the GameObject button( the new UI system of unity), like this:

alt text

SideNote : This happens when I open the project from my external Hardrive (where is saved), but If I'm on a different computer without my project (external Hardrive) and start a new project with a button and a script (with the same content) monodevelop recognize Interactable.

button.png (64.0 kB)
avatar image M-G-Production · Dec 05, 2014 at 10:55 PM 0
Share

This could be name conflict as CanisLupus said! or simply resources mess... If the button is on the PC but not in the Asset's folder in the external drive, it's going to be a mess...

I suggest you to try putting your code in an Update() fonction ins$$anonymous$$d and to program a Timer... Don't forget to hit like if I helped you, no one gives me likes :'(

Anyway, good luck! $$anonymous$$ath

avatar image Okido · Mar 17, 2015 at 11:08 AM 0
Share

I know you mean well $$anonymous$$ath, but if you want upvotes, try to answer questions only if you have good knowledge about the topic. If you don't understand the problem but try to answer it anyway, you'll inevitably end up giving unhelpful or irrelevant information (or asking the asker a lot of unnecessary questions).

Best of luck :)

avatar image
0

Answer by jhrhee · Mar 17, 2015 at 03:54 PM

You should use UnityEngine.UI.Button instead of Button than all problem will be solved.

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
  • 1
  • 2
  • ›

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

9 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Animator.Update High CPU Usage on Unity 5 resulting in bugs on Android 0 Answers

How do I access a button component 1 Answer

Why won't my function show up in the onClick area of a button? 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