x


Scene layers as Enum

Is it possible to declare an Enum containing all the Scene's layers (which would optionally be updated if/when layers change/are added removed) ?

Basically I'm working on a little script that plays sounds when a GameObject collides with another object, and in some cases I want to check if the gameObject has collided with a Collider from a specific layer.

Ideally I'd like to be able to choose which layer from said Enum in a public variable so I won't have to code any layer-specifics into the script.

Thanks.

more ▼

asked Oct 12 '11 at 08:35 PM

tinnermans gravatar image

tinnermans
16 1 1 1

I too am very interested in this idea!

Feb 29 '12 at 01:35 AM numberkruncher

Layers are already stored as a bitmask- it's a very straightforward conversion. However, I wouldn't try making an enum that can be 'updated' as layers are changed or updated- once an enum has been declared, it can't be changed. Why would you have to code 'layer-specifics' into your script? There's no reason why you can't just make a public LayerMask object, and compare against that.

Feb 29 '12 at 01:43 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
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
x129

asked: Oct 12 '11 at 08:35 PM

Seen: 762 times

Last Updated: Feb 29 '12 at 02:17 AM