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 garthhumphreys · Oct 23, 2014 at 06:47 PM · buttonscenes4.6

Unity 4.6 Button onClick not working in Scenes

I have 3 scenes setup:

  • Splash

  • Menu

  • Story

There's a coroutine setup to wait 5 secs then load the Menu scene. The Menu scene has a canvas with a button along with the automatically added EventSystem. From my GameController script I can attach a onClick.AddListener to the button which loads the next scene (Story scene) when clicked.

But on the Story scene I can't get the onClick.AddListener to work, it seems to not be triggering when the button is clicked. The Story scene has the same setup as the Menu scene (Canvas, Button, EventSystem).

I'm not sure if it's a bug of Unity 4.6 or I'm just doing it wrong. Can I have different Canvas/Buttons in different scenes? Thanks

  • UPDATE -- **

I think I fixed it. I think I was referencing the wrong thing. I was doing this

 btn = GameObject.FindObjectOfType(typeof(Button)) as Button;
 btn.onClick.RemoveAllListeners();
 btn.onClick.AddListener(SceneTransition);

This worked fine in the first scene (the Menu scene) but didn't on the Story scene. I used the Debug.Log() function to trace what was in EventSystem and notice that it was not changing to the new button in the Story scene.

So after some more head scratching I thought about doing this:

 nextBtn = GameObject.Find ("Next");
 nextBtn.GetComponent<Button> ().onClick.RemoveAllListeners ();
 nextBtn.GetComponent<Button> ().onClick.AddListener (SceneTransition);


And now it works! So I first find the GameObject and find it's component, which is a button and remove any existing listeners then add the new one, simple right!?

Thanks to all that took the time to check out my question :)

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 CanisLupus · Oct 25, 2014 at 11:25 AM 1
Share

Glad you solved the problem :) You could create an answer to your own question with the contents of your post update, and then accept it as the correct answer. This way, people will immediately see the question as "answered" :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ekoguy · Mar 19, 2021 at 05:39 PM

Guys why I dont know but onclick just unworking in specific buttons. The brightness of button should change when mouse cursor hits the button but just didnt work. I wrote "button.getcomponent().enabled = true;" to void update too but unworking again. Please help me.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can't change UI Button Listeners 1 Answer

ArgumentException: method return type is incompatible 1 Answer

How to create a button for every supported resolution? 1 Answer

Go to next scene when correct answer 3 Answers

4.6 UI Change what 'Spacebar' is doing by default 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