Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Jul 02, 2018 at 07:56 PM by DJGhostViper for the following reason:

Other

avatar image
0
Question by DJGhostViper · Jun 23, 2018 at 10:05 PM · raycastlayerslayerlayermaskignore

How to create User layer that acts like the "Ignore Raycast" layer?

Im trying to create another layer that acts exactly like the built-in layer "IgnoreRaycast". Ive been trying to figure out how to correctly do this but still not sure how. I have two layers Ive created that I would like to act as Ignore Raycast layers. The layers I would like to ignore are layers 20 & 21. The layer "unitmask" is picked inside the inspector when looking at the character.

Below: OnMouseOver works correctly but when leaving the character's "unitmask" the OnMouseExit doesn't work because it is hitting the layers I want to ignore. How can I Ignore layers 20 & 21?

 public LayerMask unitmask;
 public int IgnorelayerF = ~(1<< 20);
 public int IgnorelayerE = ~(1<< 21);
         
         public void OnMouseOver(){
         
                 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                         if (Physics.Raycast (ray, out hit, Mathf.Infinity, unitmask)) {
                         
                     print ("Hit unit mask");            
     } 
 }
             
             public void OnMouseExit(){
         
                 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                         if (Physics.Raycast (ray, out hit, Mathf.Infinity, IgnorelayerE) || Physics.Raycast (ray, out hit, Mathf.Infinity, IgnorelayerF)) {
                     
                     print ("Not hitting unitmask");
                         
         }
 }
         
             
     
     
 

Comment
Add comment · Show 1
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 Cherno · Jun 23, 2018 at 10:37 PM 0
Share
  1. Set a Layer$$anonymous$$ask to exclude the layer and use with you Raycast.

  2. Use Physics.RaycastAll to get all colliders a ray hits (depending on the Layer$$anonymous$$ask), and the nloop through them and ignore a collider that has the layer you don't want to hit.

1 Reply

  • Sort: 
avatar image
0

Answer by kumar3087 · Jun 24, 2018 at 02:20 AM

You can do it in another way like this, make a variable of type LayerMask, it will be same as camera's culling mask var, now deselect all the layers which are not required to hit, and pass this variable in your raycast.

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 DJGhostViper · Jun 24, 2018 at 04:15 AM 0
Share

I wish it was like that but its not I can only pick one layermask and thats the one the character can get assigned to @kumar3087

avatar image kumar3087 · Jun 24, 2018 at 08:08 PM 0
Share

please check this link, I've selected more than one layer, and only these selected layers will be hit, other will be ignored. https://www.dropbox.com/s/needfforqsh4jy0/Screenshot%202018-06-25%2001.37.54.png?dl=0

Follow this Question

Answers Answers and Comments

124 People are following this question.

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

Related Questions

LayerMask for RayCast 1 Answer

Layermask (raycast) wont work... 4 Answers

Detecting that I'm clicking a unit even though I'm not? 0 Answers

Can't Ignore a Layer when raycat 0 Answers

Ignoring an object (using raycast with layers) is not working 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