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 DeadCoyote · Mar 20, 2017 at 01:17 AM · uibuttononclick

Calling preset Button OnClick events from another script

Hi everyone. So, i have a UI Button, that makes some actions when pressed. Those actions are set by the interface, not by a code. And i have a Script, that handles pressing keys on keyboard.

I need the Script to "press" the Button (execute all commands attached to it), when a Key is pressed. Is there a way to do so? I can't find any built-in function, associated with buttons, that would handle 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

3 Replies

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

Answer by RobAnthem · Mar 20, 2017 at 02:46 AM

Also, to manually run the click event, you get the reference to the button and then you can run.

 myButton.onClick.Invoke();
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 DeadCoyote · Mar 20, 2017 at 06:59 AM 0
Share

Yeah! That's it! Thanks a lot.

I'd mark it as an answer, but i jus don't see such an option for the commentary - only for the main post.

avatar image RobAnthem · Mar 20, 2017 at 08:16 AM 0
Share

No problem sir.

Converted to answer.

avatar image DeadCoyote RobAnthem · Mar 20, 2017 at 05:22 PM 0
Share

Thank you again, sir. And here you go: your very own "Best answer" reward!

avatar image
0

Answer by Commoble · Mar 20, 2017 at 01:19 AM

You're looking at this from the wrong perspective: The keyboard script shouldn't activate the button, the keyboard script should activate whatever function the button also happens to activate.

For example, instead of

Keyboard script -> Button script -> Action

You should have

Button script -> Action

Keyboard script -> Action

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
0

Answer by ToyBrain101 · Mar 20, 2017 at 05:53 AM

Hello,

I think, leave the key script separate. Call scripts from the button OnClick() function. here you can add any of your scripts for the button to interact with.

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

6 People are following this question.

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

Related Questions

Reference For Button Which Calls OnClick 4 Answers

button.onClick.AddListener(method); NOT Working 1 Answer

Button.onClick.AddListener(() => Attack()); isn't running function math correctly 1 Answer

Runtime UI button creation: can't make an "OnClick" where I call a function from another script while sending a parameter. 2 Answers

Weird behaviour when trying to dynamically create buttons 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