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 /
avatar image
0
Question by kkrac · Apr 28, 2017 at 02:49 PM · uiinputcanvasui image

Block Input.GetMouseButtonDown() when clicking on UI element

Sorry if this has been asked-answered before. I wasn't able to find the right solution yet.

Context: I have a list of images in the screen Canvas. Each image is a slot of a sort of inventory and they have a script attached that implements IPointerClickHandler.

I have a player gameobject with a script which in the "Update" evaluates if Input.GetButtonMouseDown() was triggered to move or attack the player to the point of the terrain clicked.

When I click on one of the images with the script that implements IPointerClickHandler, the script of the player is also triggered, so the player moves, which I don't want to happen. How can I avoid the Input.GetButtonMouseDown() from getting triggered?

I read somewhere about CanvasGroup. Not sure if it is the solution for this, but I tried it with no luck.

Ideas? Thanks

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

Answer by ADAMN721 · Apr 28, 2017 at 03:31 PM

It sounds like you just need to disable that script when the UI is open. I'm assuming you have a script which handles opening and closing your UI. Just add a reference to the script needing to be disabled and disable it when the UI is opened. IE.

 Player.Getcomponent<MoveScript>().enabled = false;
Comment
Add comment · Show 2 · 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 kkrac · Apr 28, 2017 at 03:37 PM 0
Share

No, this wouldn't work. The UI is always visible at the bottom of the screen. Anyway, there has to be a more elegant solution than this. I believe CanvasGroup could be the way but I couldn't make it work, I was probably using it the wrong way.

avatar image ADAMN721 kkrac · Apr 28, 2017 at 03:39 PM 0
Share

If the UI is always visible then you need to be detecting for focus on the UI. So in that case, you need to check for when the player clicks on the UI or however they first interact with it and disable in the same manner. Concept would be the same, just a different trigger depending on how they interact with the UI.

Although thinking about this after the fact it sounds like it could be annoying. If the player is in a fight and accidentally clicks the UI at the bottom and controls become disabled? $$anonymous$$ay want to base this off a key press or something to avoid that miss clicks.

avatar image
0

Answer by kkrac · Apr 30, 2017 at 12:10 AM

Can anyone help on this one?

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 DTek · Feb 27, 2018 at 05:50 AM 0
Share

Ins$$anonymous$$d of using : IPointerClickHandler , simply use IPointerDownHandler. IPointerClickHandler takes place AFTER the regular Update, while IPointerDownHandler takes place BEFORE the regular Update.

 public void OnPointerDown(PointerEventData ped)    { // add content here; }

Sorry for being late to the party, hope this helps :) .

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Canvas not filling up the whole screen in Unity 5 0 Answers

Set different sorting layer for each child of a canvas, (Background and UI) 2 Answers

Control UI Input Field entirely with code? 1 Answer

Can i treat multiple image components as a single image? 0 Answers

Problem with Images during Method-Call 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