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 Pierre 1 · Mar 26, 2012 at 05:32 AM · mousemoveclickinterface

Prevents a mouse click on interface to trigger a click to move script

Hello all !

I have a classic click to move script (I am using Camera.main.ScreenPointToRay (Input.mousePosition); to detect the destination of the character)

However, I'd like to disable this script when my mouse is over interface elements (such as buttons, textures, etc.). For the moment, when I click on a button somewhere on my interface, it gives a move order, which is pretty annoying :)

Is there an easy way to do it ? (such GUI.depth or something like that which would prevent this behavior ?)

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

1 Reply

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

Answer by xarasu · Jun 20, 2012 at 05:18 PM

I was looking for something similar but couldn't find a clean solution either. I've done it three ways.

  1. Have a certain area of the screen designated for UI elements, say the bottom 40 pixels. Then in your move script, check to make sure it's above these 40 pixels and only do movement then. You can have some sort of texture over this area to help designate to the player that clicking there doesn't do anything.

  2. Similar to the first, but a little more complicated. You can also store a list of rects that you add to each time you show a UI element and loop through it in the move function to make sure the mouse position isn't hovered over a UI element.

  3. Inside the the move script have a bool for interfaceClicked. In each of your buttons actions you would need to set this bool to true, then in the move script's update function before you check for Input.mouseUp (or w/e you use to check for mouse clicks), if the bool is true, set it to false and return.

Script for the Button

 if (GUI.Button ( new Rect (x, y, width, height), "Button Label")) {
             MovementScript.selectedInterface = true;
             doAction()
 }
 

Movement script

void Update () { // Don't move if an interface was selected if (selectedInterface) { selectedInterface = false; return; }

 // Selection
     if ( Input.GetMouseButtonDown(0) )
     {
         moveUnit();
         }
 }
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 Pierre 1 · Jun 20, 2012 at 06:51 PM 0
Share

It's quite strange that there is nothing planned for this in Unity... Anyway, your solutions are correct.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to disable click to move on interface elements ? 0 Answers

mouse clicking on the plane and drag to other position 1 Answer

Click-to-move problems, mouse cursor moving 3 Answers

Move object towards mouse but if mouse moves object fallows it's original path 0 Answers

Move on mouse click in Orthografic 30x45x0 angle 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