Most u3d game development requires the Ngui interface control, Ngui how to coexist with 3D objects is the most frequently asked question when using U3D.
The author in the current project also need to add a background image, so here will be a unified approach, the hierarchy requirements are: Background image (bottom)--3d object (middle)--ngui control (top)
Here are the procedures:
1. First consider the coexistence of 3D objects and Ngui, then first new scene
2. Regardless of main Camera, let's set the Ngui section, create a 2D UI, and drag a Ngui button in.
Create a cube represents a 3D object in the scene, in order to clear the hierarchy, we put the cube in the main camera, the main camera under the 3D object, the UI root is the Ngui control.
Then hit a light, let the 3D object clear point, the effect is as follows:
3. Now at first glance it seems to be a good effect, but it will be found that if the Ngui panel is also in the view of main camera, you will see two buttons, so we set the layer so that the UI root is maintained in the UI layer, Maincamera under the default
Then remove the UI layer from the main camera's culling mask, so that the main camera does not see the Ngui control of the UI layer, and the Ngui control only has its own camera to render, and the subsequent settings are convenient for the main The camera's clear flags are set to depth only so that the cameras ' hierarchies are available.
The 3D object is in the middle layer, so here the depth of main camera is set to 0,ui root camera depth set to 1 (topmost), depth is the order of rendering, the larger the later rendering.
At this point, 3D objects and Ngui controls have co-exist, moving under 3D objects can be found Ngui controls are always covered above
4. Then set the background image, then create a camera, named Bgcamera, and then create a new layer, the BG layer (how to create a new layer is the basic operation is not said here), the Bgcamera into the BG layer
5.create a panel, used to make background images, adjust the position angle (within the Bgcamera field of view), also into the BG Layer, and placed under the Bgcamera
6. Next similar setup under Bgcamera
Depth set to-1 (lowest level)
7. At this point there is a BG layer, remember to go to the main camera where the BG layer is removed
8. At this point, the settings on the scene is over, so there is a background, and often the background is the need to dynamically capture the screen resolution to fill the entire interface, so here I add a script to add a new script on the plane BG.cs, the script content is as follows:
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classBg:monobehaviour {5 //Background Map6 Publictexture2d bgtexture;7 //Use this for initialization8 voidStart () {9Gameobject.addcomponent<guitexture>();Ten } One A //Update is called once per frame - voidUpdate () { -Guitexture.texture =bgtexture; theTransform.localscale =NewVector3 (0,0,0); -Transform.position =NewVector3 (0,0,0); -Guitexture.pixelinset =NewRect (0,0, Screen.width, screen.height); - } +}
Then assign the required map to this public variable
9. Run a look at the effect:
10. The effect is complete, and finally the details are adjusted, that is, multiple camera is bound to an audio Listener and flare Layer, just leave one, you can choose to Bgcamera and UI root camera of the two hooks removed
Finished, the sound, looks longer, in fact, as long as the understanding of the concept of depth rendering, it is easy to set up a relatively basic explanation, there are not clear friends can also comment below, I will take the time to answer, thank you support!
Cowill
"Base" unity in background, 3D object, Ngui control coexistence