- Home /
(Mobile) Raycast still ignores everything instead of objects with specified layers
Hi.
The problem is that I need to detect which object I hit when touching the screen but nothing gets detected.
I have a plane all the shapes land on. The plane is surrounded by empty game objects with big colliders (kind of borders). The point is that all these objects have the layer I ignore.
This is the code:
newTouch = Input.GetTouch (0);
Ray ray = Camera.main.ScreenPointToRay(newTouch.position);
int layerMask =~( (1 << 8) | (1 << 10));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, layerMask)) {
nameOfTheClickedShape = hit.transform.root.gameObject.name;}
The problem that it still ignores the objects with the 9th layer and I have no idea why.
Hope my explanation is clear.
Thanks.
Comment
Answer by Neitrosha · Mar 25, 2014 at 02:52 PM
Solved.
if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 9))
Your answer
Follow this Question
Related Questions
Click Object under another Object 1 Answer
Gameobjects in Ignore Raycast layer still get hit by raycast. 1 Answer
Ignore raycast from specific object? 1 Answer
Ignore Raycast not detecting collision?? 1 Answer
OnMouseDown, Raycast, Error 3 Answers