x


Check if Layer is in Layermask?

How can you tell if a LayerMask contains a given layer.

more ▼

asked Mar 03 '11 at 01:57 AM

Patyrn gravatar image

Patyrn
542 49 54 64

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
var layermask : LayerMask;
var layer : int;

function Start () {
    if (layermask.value & 1<<layer) {
        Debug.Log ("Layer is in layer mask");
    }
}
more ▼

answered Mar 03 '11 at 02:54 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

I'm not sure how to get this working. Is the & supposed to be &&? I'm also writing in C# (Forgot to mention that). What return values am I checking for on either side of the &?

Mar 03 '11 at 03:53 AM Patyrn

Figured it out. Thanks!

if ((layersCheckedForTargets.value & <<layer) == 0) {}

Mar 03 '11 at 03:59 AM Patyrn

Er sorry for my application I needed to see if it was NOT in layer mask. Above would be != if you wanted to check if it WAS in layer mask.

Mar 03 '11 at 04:00 AM Patyrn

Yeah, C# doesn't seem to cast to bool automatically like that.

Mar 03 '11 at 05:34 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x150
x42

asked: Mar 03 '11 at 01:57 AM

Seen: 2203 times

Last Updated: Mar 03 '11 at 01:57 AM