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
2
Question by ina · Aug 31, 2011 at 08:36 AM · guiraycast

Prevent Raycast on reacting to GUI input?

So in the 3d space of my game, raycast from mouse is suppose do something - but is it possible to disable this raycast behavior when the user is interacting with a GUI on top? i.e., to have the GUI be a "layer" to prevent the raycast from going off?

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
1

Answer by Nerull22 · Aug 31, 2011 at 12:32 PM

Just for future reference if you supply some scripting examples, that would help us help you more (Does the Tom Cruise laugh).

However, basically I'm guessing that you have the raycast being sent whenever you press the left mouse button, but don't want it sent when the player is interacting with a button or something else on the GUI layer. Basically, you are going to have to put in a check to see what the mouse is currently over to tell the program whether or not it should fire the raycast or not. So something like:

 if(Input.Button == "Fire1" && !overGUIElement)
 {
      //Fire raycast code here.
 }

I'm hoping that this will help and is indeed the question tht you were asking. IF it isn't the answer you're looking for, post back with some code for us to look at, and the community will be able to help you more effectively.

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 ina · Aug 31, 2011 at 10:28 PM 0
Share

This is basically what I am asking, but I am not sure if Unity GUI has any methods for detecting when a mouse is over a GUI button... (as opposed to when it is pressed)

avatar image
1

Answer by Nerull22 · Sep 02, 2011 at 12:48 PM

There is, sorry I should've put that in with my answer. It's a function that you can call that is extended from MonoBehaviour. Just put in the function:

 void OnMouseEnter(){}

And that function will initiate whenever the mouse if over a GUI element. Also you may want to add some code for when the mouse leaves the GUI element which you can use:

 void OnMouseExit(){}

So if you have a boolean in the script to detect whether or not it's over a GUI element or not, then you can just put:

 private bool overGUIElement = false;
 
 void OnMouseEnter(){overGUIElement = true;}
 
 void OnMouseExit(){overGUIElement = false;}

So now all you have to do is check against that boolean in your update and you'll be able to judge whether or not the player is hovering over a button or not. Hope that finishes up the question, if not just comment again.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GUI.button and onClick Terrain 2 Answers

Trouble targeting GUI with raycast 0 Answers

Raycast from GUI Camera possible to only effect gui? 1 Answer

Raycast and GUI question 1 Answer

Touch performance: Multiple raycast-scripts or better only one 1 Answer


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