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 mabit · Jun 21, 2011 at 05:24 PM · raycastclick

Click Object under another Object

I have an issue where objects appear in the game world that player can click on to collect, however these appear randomly and enemies can wander over them so they cannot be clicked.

I have tried putting them on different layers but I cannot have them on the IgnoreRaycast layer as the player has to drag them into the game world and then they are effected by different physics relevant to them, so just changing their layer is not going to work.

Is there a way that once the object was placed that you could do something like.

Code I wish existed

"gameObject.IgnoreRayCasting = true;"

Or can anyone think of a way round this issue. My desk has a head shaped indent in it.

Comment
Add comment · Show 4
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 Heratitan · Jun 21, 2011 at 05:38 PM 0
Share

Do you need to drag the enemies around or drag the objects to collect around?

avatar image mabit · Jun 21, 2011 at 05:55 PM 0
Share

I have 3 kinds of object in my game, Enemies(the player never clicks them), Helper Objects( When Instantiated they follow the raycast until the player clicks them to place them), Collectible Objects(They spawn at random positions and the player then clicks them).

If I only have the Collectibles visible to the raycast then this stops the Helper Objects following the mouse until they are clicked.

Or is there something about layer masks I am overlooking?

avatar image Dreamblur · Jun 21, 2011 at 06:01 PM 1
Share

$$anonymous$$y comment (reply) also got deleted when you deleted your answer. XD

Anyway, short version of my previous comment:

layermask = layermask1 | layermask2; // combines 2 layermasks into 1

avatar image mabit · Jun 21, 2011 at 06:03 PM 0
Share

Thanks for the code that helped a lot. And sorry for deleting your last comment, I got the e-mail though.

1 Reply

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

Answer by Dreamblur · Jun 21, 2011 at 05:42 PM

Why would changing their layer not work? You just have to force the raycast to only detect a particular layer (the collectible's layer) and ignore all other layers. You can do that by simply passing a layermask parameter into the Raycast method.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Ignore Raycast not detecting collision?? 1 Answer

I need the x, y, z position value of the point of gaze input (pointer click in google vr) on a plane centered at (0,0,0) and scaled (2,2,2), 0 Answers

How to make constant click position ? 0 Answers

How do you use a queuing mechanism in Unity? 1 Answer

Detect if object clicked on 2 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