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 siddharth3322 · Jul 27, 2016 at 10:53 AM · uibuttontouchclickeventsystem

Detect UI Button Click Event in Update method

At present Update method of script controls movement of main player. Game HUD panel contains Pause button of game play pause functionality.

When I click on Pause UI Button, player also detects that touch and take its movement regarding that. So I want to remove this part. So in Update method if I detect this Button click event than I can ignore this irregular movement of player.

How to detect this?

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

Answer by LCStark · Sep 20, 2018 at 04:12 PM

Not sure if it'll work for touch input, but for mouse clicks I use EventSystem.current.IsPointerOverGameObject() to detect when the mouse is over UI element and stop any gameplay actions.

EDIT

using UnityEngine.EventSystems;

...
void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { // player action } }
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 siddharth3322 · Sep 20, 2018 at 04:15 PM 0
Share

yes you are in right direction but add full code here so I can mark this as correct :)

avatar image LCStark siddharth3322 · Sep 20, 2018 at 04:20 PM 0
Share

Is that alright? :)

avatar image siddharth3322 LCStark · Sep 20, 2018 at 04:21 PM 0
Share

I also require to check back - what is exact solution for this !!! But you are in right path :)

avatar image
0

Answer by Humanhoney · Sep 20, 2018 at 02:42 PM

Create public method with boolean input variable. Add to your button EventTrigger component. On your pause button assingn this script. If you need release and pressDown assign one with "true" and other with "false". Or run method ChangePauseState.

Example:

  private bool isGamePaused= false;
     
     private void Update()
     {
              if(isGamePaused)
              {
                   //Do something...
              }
     }
     
     public void ChangeCurrentPauseState()
     {
           isGamePaused = !isGamePaused;
     }
     
     public void ChangePauseState(bool _value)
     {
           isGamePaused = _value;
     }


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 vincismurf · Sep 20, 2018 at 03:37 PM

Or add a listener

public Button = but = null;

void Awake() { if(but) { but.OnClick.AddListener(OnButtonClicked); } }

public void OnButtonClicked() { Debug.Log("Button Clicked"); }

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 siddharth3322 · Sep 20, 2018 at 03:44 PM 0
Share

Basically, you both moving ahead into the wrong direction, I already knew how to detect the click event and detect this event in the update method.

At that time, when I was pressing the pause button, a game player also detect this input and behave based on that input.

So I want the UI detection system in this way - when I press the pause button, it only remains for that click event - not detected by the game player and change the direction.

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

90 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 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

Holding down UI Button and shooting raycast from touch position doesn't work simultaneously:(( 0 Answers

Button is not being clicked. 1 Answer

Only want to detect button click event 1 Answer

How to set UI button as selected on mouse over 1 Answer

How to get the fingerID (Touch) that is pressing a specific UI button. 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