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
0
Question by CastleIsGreat · Feb 24, 2015 at 07:27 AM · buttonuser interfaceonclick

Having issues determining a way to use buttons in a script.

Hi, first, I do know that you can use On Click() and add in functions and various things, but to me that seems very complicated and just not programmer friendly... atleast the way I'm looking at it.

So I've tried a couple of things but I cant seem to find the right function for what I'm trying to do.

Basically I want something I can use to trigger an if statement, when I press a button down. Currently I've tried OnPointerDown, but it seems that it is an event and not a Bool value, and unfortunately I do not understand the event system. In anycase if anyone could help in giving me an idea of how I can do this that would be awesome!

Also worth noting button is not noticed as a component in declaration unless declared as seen below, not sure if thats a bug... IE "Button Quit;" I imagine the code would look something like this.

 using UnityEngine;
 using System.Collections;
 
 public class quit : Monobehaviour{
 
 public UnityEngine.UI.Button Quit;
     
 void start(){   
 Quit = GetComponent<UnityEngine.UI.Button>();
             }
 void update(){
 if (quit.MAGICFUNCTIONRELATEDTOCLICKING == true){
 Debug.Log ("Application was exited");
 Application.Quit();
 }
 }
 }





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

2 Replies

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

Answer by CastleIsGreat · Feb 25, 2015 at 05:28 AM

I ended up writing a function to handle it using the event system, though I definitely was not asking for information on that. I'd still like another way to do it by using the button to flip a bool value for ifstatements. In anycase, I'm using sendmessage to call functions instead...

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 tanoshimi · Feb 24, 2015 at 07:30 AM

Rather than guessing, I recommend you follow some tutorials about how to use the UI system: http://unity3d.com/learn/tutorials/modules/beginner/ui

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

2 People are following this question.

avatar image avatar image

Related Questions

OnClick() problem with Button script: "Deleting an array element will copy the complete array to all..." 1 Answer

Canvas button with 2 functions onClick must be pressed twice for 2nd function? Will not disappear? 1 Answer

How to ADD one Buttons.onClick events to another Buttons.onClick? 1 Answer

Show UI Button press color from script when invoking onClick 2 Answers

Looping through Button Array and checking for OnClick 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