Layers Layer:
From the layers setting, it supports up to 32 layers. The values of the layer begin with 0^2,1^2, 2^2, and 3^3 in turn.
When the camera culling the Mask property
Nothing=–1
Evening = sum of all layers, the project starts with 7 layers set by default. The value is 0^2,1^2, 2^2, 3^3:6^2 = 279
If we choose the Defulat layer, the No. 0 position value 0^2 = 1
If we choose Defualt,transparent, the layer position 0,1 = 0^2+1^2 = 3
Combination:
Suppose this happens in the game: a,b,c we need to design a number to represent the [A,B,C,AB,AC,BC] 6 combination, we just need to put a=0,b=1,c=2. Based on the number of ^2 parties
A = 0, B = 1, C = 2,ab = 3,ac = 5,BC = 6
This allows us to know by a numeric value what permissions the role has.
A ray is emitted to the screen to detect collisions with the object:
Raycasthit get information about touching an object
Ray defines the rules for the Ray
Send a ray to the screen
BOOL Physics.raycast (Ray ray,out raycasthit hit, float distance, int layermask)
Code:
usingUnityengine;usingSystem.Collections; Public classTest:monobehaviour {Private intindex =0; //Use this for initialization voidStart () {intindex = Layermask.nametolayer ("Uimode"); } //Update is called once per frame voidUpdate () {Raycasthit hit; Ray Ray .=Camera.main.ScreenPointToRay (input.mouseposition); //with the mouse as the origin, to the world to launch a 100f length of the ray, only the Uimode layer of the object to collide if(Physics.raycast (Ray, outHit , 100f, index)) {Debug.Log ("objects colliding to the Uimode:"+hit.collider.gameObject.name); } }}
Unity Screen Ray collision