[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”)


if (hit.transform.gameObject.layer == LayerMask.NameToLayer("examplelayername")) {
  // Do something for this layer