Learning Unity 3D First week, the goal is to create a small scene, with a role controller to walk in the scene; the second is to write a simple mobile script.
First, create a small scene, with a role controller to walk in the scene
1. First install Unity 3D 5.3 version. Then create a new project, the default created a scene, just save a moment on it;
2. First drag a cube or sphere, and then practice the whole drag (Q), according to the x y Z axis drag (W), rotation (E), zoom Out (R);
3. Import some Unity 3D own resources or download in the store, direct import and then drag and drop can be used. This will make our scene look better. It is necessary to understand some of the perfabs as a preset combination, you can drag and drop the direct use of models as a model, but also need to render, scripts for the script, material for the material; I'll make an error after a resource bundle: System.IO.File does not contain A definition for ' readaubytes ', a similar error as long as you do not select Web Player in the file build settings.
4. The role controller can use the unity of its own resources, import package character can. We can drag the first and third view of the character model, and then press WASD and control can be controlled. It is important to note that the y of the character model must be greater than 0 to ensure that the character model is on the ground, otherwise the model will automatically sink when it starts to run.
5. The cube we add is actually a gameobject added mesh Filter. We can create the component of the scene ourselves, by adding a gameobject→ add the component mesh filter to add the shape → add mesh renderer→ add materials→ Add Texture (5.3 version Click Albedo before the dot can be selected)
Follow the steps above to create a small scene, with a role controller to walk in the scene, but the lens is fixed, can not follow the character model for conversion. Unity also provided the lens of the script file, I now only learned two. One is mouse Orbit: mouse follows. The camera object follows the mouse and moves as if it were not locked in LOL; the next one is Smoothfollow: Smooth following, the camera always follows the parent object, just as LOL locks the perspective. The next thing I learn is to control a perfabs to move, add Smoothfollow, drag the script to the camera, and then the object to Perfabs.
Second, write a simple mobile script
Here I'm just telling you the basics of this script.
1. Creating objects
Gameobject obj;
2. Combine the object with the Perfabs in the start function:
obj = This.gameobject;
3. Add the If statement to the update function, accept the button clicked from the keyboard, if it is a W or s on the pan, the main statement is (speed need to own public float, W is forward, S is back):
Obj.transform.Translate (VECTOR3 * forward *time.deltatime * speed);
4. If you click on a or D then the rotation will occur, the main statement is (Y also need to define their own, representing the rotation of the angle, if it is a will occur negative rotation, D is rotating):
y=-time.deltatime *speed;
5. The next step is else, the specific statement is:
y=0;
Obj.transform.Rotate (New Vector3 (0,y,0));
Obj.transform.rotation = Quaternion.slerp (obj.transform.rotation,rotateto,time.deltatime);
There are several functions in this script, such as translation function, rotation, time increment all need to study their own learning, at present I have not learned very thoroughly, but I recite it ~ ~ ~ ~ ~