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 mabit · Jun 03, 2012 at 05:59 AM · guiraycastbutton

Stop RayCast Passing thru GUI

I have a GUI where players select what they want to place in the game world. Once selected a ScreenPointToRay places the object in the world on mouse click.

The problem is that when you click the button, the ray passes thru the GUI and places the object in the world under the button.

Is there a way to stop the ray passing thru the GUI?

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

4 Replies

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

Answer by whydoidoit · Jun 03, 2012 at 08:42 AM

For this answer i presume you are using OnGUI and that isnt going to detect your raycast so it Sounds to me like you need a simple state machine for placing the items. When the button is clicked set a Boolean value = true then don't do your ray cast until you find that value. Reset it to flase when you have placed your object. I presume at the moment the raycast is always happening.

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 mabit · Jun 03, 2012 at 09:20 AM 0
Share

Yeah, the OnGui works wonders for everything but this. I have a work around, I am not to happy about though.

I have just tried putting an object in front of the camera but that did not seem to work.

Having spent hours trailing the forums it has been an issue that has been brought up since unity 2.0. People were hoping when OnGUI was introduced this would be fixed but sadly not.

avatar image ppiatek · Aug 08, 2015 at 01:42 AM 0
Share

For me it works. But I reset this value at the end of Update() after checking it.

avatar image
1

Answer by GuyTidhar · Jun 03, 2012 at 07:00 AM

You should be using a layer to define the GUI object that you do not want to raycast against.

This way, when you do the raycast, you will tell unity to exclude any object that is set with that layer.

Layer mask:

http://unity3d.com/support/documentation/Components/Layers.html

Raycast:

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

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 mabit · Jun 03, 2012 at 08:18 AM 0
Share

Sorry been at it for 16 hours, So I may not be explaining things correctly. I dont want it to pass thru GUI the raycast should be stopped by the GUI.

avatar image GuyTidhar · Jun 03, 2012 at 08:24 AM 0
Share

You want to test the raycast only against the gui?

If so you just need to use the 'Raycast()' method of a collider in the shape (or bounding shape) of the gui element against which you wish to check for ray hit (collision between the ray from the screen and the collider of the gui):

http://unity3d.com/support/documentation/ScriptReference/Collider.Raycast.html

avatar image
1

Answer by fafase · Jun 03, 2012 at 08:50 AM

The way I get it, you wants the gui to lay in the corner and be able to click on it any time and place the object without any other manipulations.

Maybe you could try to check the position of the mouse pointer on the screen and when clicking if it is at a certain position (gui position), then you have the gui options, any other position you are placing on the world using raycast.

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
1

Answer by FadeToBlack · Jun 03, 2012 at 01:18 PM

check this question http://answers.unity3d.com/questions/120980/unitygui-click-event.html#answer-261746 i made it through GUIUtility.hotControl

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with GUI Buttons with WorldSpace Canvas 2 Answers

Select a game object and perform actions using GUI.Button (EventTrigger) 2 Answers

Why does my UIButton needs a raycaster if the parent has one? 0 Answers

[Logical Error] Select a game object and perform actions using GUI.Button 1 Answer

Disable one GUI Button with my Mouse Scroll Wheel? 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