- Home /
[solved] Raycast get which layer was hit
Hello community, i'm currently using an Physics.Raycast in order to detect an object which works fine, now i want to make the raycast detect two layers, in order to execute seperate tasks. my question is, how do i distinguish between the two layers like in this draft below?
if (Physics.Raycast (ray, hit, Mathf.Infinity,twolayered))
if(hit.transform == layer1) <-- how is this setup?
do this
if(hit.transform == layer2) <-- how is this setup?
do that
i've tried something like: hit.transform.layer == LayerMask.NameToLayer("examplelayername")
Answer by robertbu · Dec 29, 2013 at 04:56 PM
Try:
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("examplelayername")) {
// Do something for this layer
}
Argh!, yes it works thanks, i'm suffering from the 'too-long-scripting-syndrome' forgetting to set layers, forget debug messaging etc etc..time for a brain cool
Your answer
Follow this Question
Related Questions
ray cast returning the wrong object, going through multiple objects 1 Answer
Is there a generalized version of GUIUtility.hotControl? 0 Answers
Detection where light hits using SphereCast 1 Answer
Can Raycast get multiple points from the same collider? 1 Answer
How to do different actions when hovering mouse at each button on GUILayout 1 Answer