Unity Study Notes 4: complete Prefab And add First Person Controller and unityprefab

Source: Internet
Author: User

Unity Study Notes 4: complete Prefab And add First Person Controller and unityprefab
I haven't learned anything for a long time and used my blog to record it. I have been very lazy this year and I am approaching the start of school. I also need to adapt to it and write something in advance so that I can better enter the state of school ~~
In this note, we will create a better Prefab and add a first-person role in the scenario. For a series of tutorials and materials, refer to the translation tutorial "Unity game engine basic getting started video tutorial" produced by the translation team. Attached to the second note.
In the previous tutorial, we created a Prefab. At last, I used four Prefab to capture multiple vertices to create a simple tunnel. This is just for the convenience of Prefab. Next we will delete this tunnel to only one Prefab (delete it from the Hierarchy view on the left), and then refine our Prefab. Our Prefab is surrounded by no physical system and no thickness, so there will be no physical collision and other effects. Things placed on the floor will fall infinitely. So we will add physical components for Prefab. First, expand PFB_Straight in the current scenario from Hierarchy, select MineShaft_Floor, and click Component, Physics, and Box Collider in the system menu to add a Box-like collision generator.


After being added, a green border is displayed on the floor, and a new Box Collider component is added to the Inspector view on the right. We will define the thickness of the collision generator according to our own situation. Here I will change Y to 0.01 in the Box Collider component Size. This depends on the scaling ratio of the imported model. If the format of the imported model is 3d max, it should be 0.1. Let's take a look at it and adjust the value to a thin layer.





After the Box Collider is set up, the object will not fall when it comes to the ground. Right-click the Assets folder to import the package Character Controller that comes with the system. This package contains the first-person and third-person roles.



We select all by default. If you do not need to change it, click Import to introduce it. After the introduction, a new sub-folder named Standard Assets will be created in the Assets folder.
Next, open the folder Standard Assets -- Character Controllers. We can see a third-person miner role and a first-person capsule-like role. You can drag the current model on the preview page in the lower right corner, as shown in the following figure.


What we need to do is drag the controller in the first person to our Scene scenario and drag it up to adjust the location.
At this point, if you click the play button above, you can freely move and adjust the angle of view in our scenario. The effect is as shown in. Because we have not set any lighting and background colors, the walls are black and the background is blue. If you keep dropping after playing the video, your Controller is too low. Just move it up.
Next, we need to standardize our Prefab. We need to make the center of the current preset body the center of the physical space and build the Prefab on the coordinate origin. In fact, there are some errors currently. Click the current Prefab And you can see these errors in the inspector view. So Let's adjust it to make our preset body more perfect. Step 1: remove the parent-child relationship in the current scenario. In the Hierarchy view, select the four child elements in PFB_Straight to drag out the PFB_Straight range. At this time, the system will prompt you, which will lose the current parent-child relationship. Click "Continue. The Hierarchy view is shown in the following figure. The child elements and the newly created game objects are all white.


Next we will select an empty game object PFB_Straight. Because we used to build tunnels or other actions, no matter the floor or ceiling wall, we didn't adjust the positions based on 0, 0 at the beginning, so first, we need to modify the coordinates of four small parts. First, select MineShaft_Floor, and adjust the coordinates to 0, 0, and then press V to drag the two walls as in the beginning, and then change MineShaft_Ceiling to 0, 0. Then, move our First person Controller to the space. Next we will select the four small parts and drag them into PFB_Straight. We will find that the preset body has not changed to blue this time.
The reason is actually very simple. We thought we had already broken the parent-child relationship of Prefab. Therefore, after we selected prefab, we clicked apply in the inspector view. When the mouse stays, it will show a detailed explanation. After you click apply, the changes will be applied to the default preset body, that is, each preset body dragged after us, with the coordinates in the physical center. Of course, we can also click the Revert next to Apply to undo it.


At this point, we have created a complete set of coordinate values and coordinate axes that are both very standard. The floor has a physical model Prefab and added a first person controller to the Prefab floor.

2015.2.27 0: 03By Mr. Losers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.