Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Chioni · Jun 01, 2016 at 02:43 PM · unity 5uibutton

UI Button-parameters inaccessable in spite of "using UnityEngine.UI"

I am trying to access any parameters on a UI-Button, but they are being highlighted red in the script and I get Errormessages altough I have "using UnityEngine.UI;" implemented in my script. Example Error: "...Type Button' does not contain a definition for interactable' and no extension method interactable' of type Button' could be found (are you missing a using directive or an assembly reference?)"

My script simplified:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class MyScript: MonoBehaviour { public Transform tButton;

void SetButtons() {

if(blabla)

{ Transform newButton = Instantiate(tButton, tButton.transform.position + v3NewButtonPosiOffset(), Quaternion.identity) as Transform; //some buttons will be instantiated aside each other

alt text}

}

}

button.png (3.8 kB)
Comment
Add comment · Show 9
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 saud_ahmed020 · Jun 02, 2016 at 07:12 AM 0
Share
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ButtonScript : $$anonymous$$onoBehaviour {
 
     public Transform tButton;
 
     void Start()
     {
         SetButtons();
     }
     void SetButtons() {
         
     Transform newButton = Instantiate(tButton, tButton.transform.position , Quaternion.identity) 
             as Transform;
             
 
         newButton.GetComponent<Button>().interactable = false;
     }
   
 }

@Chioni It is working fine. you have some other issue.

screen-shot-2016-06-02-at-121145-pm.png (120.9 kB)
avatar image Chioni saud_ahmed020 · Jun 02, 2016 at 07:28 AM 0
Share

I copied your script and it still claims it cannot find the method. What else could be wrong? I also tried reinstalling Unity. Is it something to do with my Windows? alt text

error2.png (31.0 kB)
avatar image saud_ahmed020 Chioni · Jun 02, 2016 at 07:43 AM 0
Share

@Chioni $$anonymous$$ake sure you must have Unity version 4.6 or above

avatar image Chioni saud_ahmed020 · Jun 02, 2016 at 08:44 AM 0
Share

$$anonymous$$y Unity version is 5.1.0

avatar image saud_ahmed020 Chioni · Jun 02, 2016 at 12:34 PM 0
Share

@Chioni Try exiting Unity and Visual Studio, then running it again.

avatar image Chioni saud_ahmed020 · Jun 03, 2016 at 12:18 PM 0
Share

alt text

I copied your script. This shows it cannot find the method. So what else could be wrong?

clipboard01.jpg (86.2 kB)
avatar image Chioni Chioni · Jun 02, 2016 at 07:22 AM 0
Share

Oh and it's not the scripts name (I was too fast and forgot to rename it, but it still doesn't work).

avatar image Rotavele · Jun 03, 2016 at 02:18 PM 0
Share

Which build setting are you coding in?

avatar image Chioni Rotavele · Jun 07, 2016 at 05:54 AM 0
Share

PC (Standalone)

4 Replies

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

Answer by Chioni · Jun 06, 2016 at 09:35 PM

Apparently it was a problem with my Unity 5.1.0 version (whyever). In 5.3.5 using UnityEngine.UI works just fine and Button-methods are accessable.

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 Rotavele · Jun 03, 2016 at 02:21 PM

First I'd make sure you have the button prefab/game object set up and that it is instantiating that. From what I see you're only instantiating a transform.

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 Chioni · Jun 03, 2016 at 02:56 PM 0
Share

It's just a simplified pseudo-script. $$anonymous$$y real script works fine if I leave out any lines which try to access Button()-something methods e.g. -.interactable or anything else from here https://docs.unity3d.com/ScriptReference/UI.Button.html

Btw "only instantiating a transform" why only? it's exactly what should happen; I am duplicating a public transform which is inserted in the editor. You can do that with either gameObject or Transform, it doesn't matter which one, just try it^^

avatar image alexgamble · Sep 01, 2020 at 06:19 AM 0
Share

Thank you, hadn't realised I had another script called button in my game.

avatar image
1

Answer by ninja_gear · Jun 03, 2016 at 04:25 PM

using UnityEngine.UI.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 bonasera · Jan 29, 2020 at 08:11 AM

@ninja_gear thanks it is 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

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

8 People are following this question.

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

Related Questions

Only want to detect button click event 1 Answer

How to keep your button selected after clicking away ??? 1 Answer

UIButton highlighted color not working 0 Answers

TOGGLE SCRIPT 1 Answer

how to test Buttons 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