Yes, yes, I know there’ve been multiple questions about the exact same title and topic.
However none of them helped. It’s like my Physcis.Raycast behaves in other way. To test my problem I created simple Unity project. There’re only 3 objects in it: a Sphere, a Box & a Cylinder. I also added 3 user layers of the same names. As you may suspect, Sphere is on layer Sphere, Box on layer Box, and Cylinder on layer Cylinder.
Then I created this script:
using UnityEngine;
public class HitMe : MonoBehaviour
{
public LayerMask layerMask;
void Update()
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool gotHit = Physics.Raycast(ray, out hit, layerMask);
Debug.Log(string.Format("mask == {0}, gotHit == {1}, hit == {2}",
layerMask.value, gotHit, hit.collider));
}
}
… and attached it to my MainCamera. However, regardless of what I set as HitMe.layerMask, I get hits when I hover my mouse over any of these 3 objects (even though I suspect, that mask set to Cylinder should give me only Cylinder, and NULL, when I hover Sphere, or Box, or nothing).
How come?