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 /
  • Help Room /
This question was closed Jun 09, 2016 at 06:51 PM by UndefeatedDEV_.
avatar image
0
Question by UndefeatedDEV_ · Jun 06, 2016 at 05:55 PM · strange ioc

Detecting Button Click

How do i let my game react if i press on a button

Comment
Add comment · Show 3
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 Mmmpies · Jun 06, 2016 at 07:38 PM 0
Share

Which button where? On the UGUI layer? A 3D button in game that you mouse click on? A button on your keyboard? An xbox controller button? A chocolate button from a packet you just found wedged down the side of the sofa?

Give us some more information.

avatar image UndefeatedDEV_ Mmmpies · Jun 07, 2016 at 05:01 PM 0
Share

Just a button in my canvas

avatar image Hellium · Jun 06, 2016 at 09:21 PM 0
Share

Unity provides nice tutorials about scripting, you will find your solution here :

http://unity3d.com/learn/tutorials/topics/scripting/getbutton-and-getkey?playlist=17117

1 Reply

  • Sort: 
avatar image
0

Answer by Mmmpies · Jun 07, 2016 at 05:13 PM

Alright I'll stop joking! This is really easy and more importantly really easy to search for. Watch some of the tutorials for the UI but this is the basics.

Create a script (I'll use C# for this) and in that script create a public void function. It HAS to be PUBLIC so like this

 public void PushTheButton()
 {
      print("You pressed my button");
 }

leave Start() and Update() and the rest of your script as is just add that function. Save and drag the script onto the button. Then click on the button and look in the inspector.

Click + in the OnClick area of the button and a slot appears, drag your button onto the slot (even though the slot is on the button!). From the drop down select your script name -> PushTheButton.

And that's it, if you click on the button now it'll call that function and do whatever is in it, in this case send "You pressed my Button" to the console.

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 UndefeatedDEV_ · Jun 09, 2016 at 06:51 PM 0
Share

This dint work nut i found out how

Follow this Question

Answers Answers and Comments

60 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

Related Questions

XCode Linking Errors. Unity 5.2.3f1 XCode 7.2 1 Answer

Instatiated object not being referenced in Start function? 2 Answers

Hello How can I Save Player position and a Gameobject which is a UI Text? 0 Answers

Showing a UI canvas when player enters a specific location 2 Answers

Draw snapping lines 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