x


More Layers? Selecting one out of 50+ GameObjects?

Good morning,

I am coding a board game in c# and have all of the code I need to handle the touch input of my board game pieces, except that I only seem to have 31 Layers to use, therefore my 31 layermasks to use for my ray tracing. My game uses more than 50 pieces, and I would like them all to be touchable at one point or another.

  1. Is it possible to remove a Gameaobject from a layer and add others to a Layer via code? (ie: I would have a selectable piece layer and manually assign all the pieces I want to be able to touch to that layer.)
  2. Assuming #1 is true, is it possible to return a Gameaobject value from a ray trace? This would cut down the layers I need to use dramatically!
  3. If the first two aren't possible, am I able to use more layers somehow?
  • Drew
more ▼

asked Apr 04 '12 at 06:19 PM

dr3wd gravatar image

dr3wd
15 2 2 2

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

1 answer: sort voted first

It isn't possible to use more layers. The layermask is an integer bit mask. Since an integer has 32 bits you have 32 layers.

If you had took a look into the documentation you would have found GameObject.layer which allows you to get or set the layer of a GameObject.

Also if you read the docs on Physics.Raycast carefully you will notice that there are different versions of this function. Some will return information in the RaycastHit struct you pass by reference.

now you should have all you need ;)

more ▼

answered Apr 04 '12 at 06:25 PM

Bunny83 gravatar image

Bunny83
45k 11 48 206

Thanks for the quick response, Bunny83.

I must admit, I could have read the documentation more... but after reading it as much as I have in the past week, I just felt like reaching out to someone that knew what they were doing to see if they had an answer instead. I just started with Unity a few weeks ago, and it's been one heck of a ride so far!

I appreciate the links. I will look into that specific documentation now and go from there.

Apr 04 '12 at 07:00 PM dr3wd
(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:

x151
x150
x10

asked: Apr 04 '12 at 06:19 PM

Seen: 518 times

Last Updated: Apr 04 '12 at 07:01 PM