- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
主要实现了角色的自由行走移动。下面为英文原文及简单翻译。
First things first, we need a character which moves around! Create an empty Unity 3D game project
that imports none of the unity packages which comes with the software.
首先,我们需要一个可以自由活动的角色。第一步当然需要创建一个空的unity3d项目了,创建时不要导入任何的资源包。
Open Unity > Goto > File > New Project > Name it 'EVAC-CITY tutorial'.
If you don't have it already go ahead and download the free resources needed for this tutorial here:
Download tutorial resources
Download the Example Projects
Then Open up the Unity project you have just created goto the assets folder and drag the Tutorial
Resouces folder you had downloaded and drag it into the assets folder.
Once this is done you can now save the scene Goto > File > Save Scene As...
Scene.
将所创建的项目命名为EVAC-CITY tutorial,所需项目素材在附件中,然后将所需的资源文件拖至项目assets目录下。当然,自己制作也可以。
Firstly I'm going to create an empty game object and name it 'Player', to rename an object left click
over the name of the object in your Hierarchy and keep your mouse stationary over the object after
releasing left click for a second.. Then from the menu with your new game object selected, choose
(component – mesh – mesh filter), and (component – mesh – mesh renderer). In the mesh filter I am
going to select 'plane' which is made available from adding the above .fbx file to your assets folder.
Also, select 'plane' from your project window, in the inspector look at the FBX importer component, set
the scale factor to 1 and click apply.
首先,创建一个空的物体,并命名为“Player”,选择此物体,并为其添加"mesh filter","mesh renderer" 组件。将mesh filter的mesh属性指定为刚“plan”网格。然后在项目窗口下选择"plane"物体,在其fbx导入设置中,将缩放因子改为1。
Now we need a material to render our character onto the plane! You might have noticed that when you
import an fbx file it automatically creates a material for you. I'm just going to delete what it creates
and create my own and name it 'PlayerMaterial'. Right click the project window and create a new
material. Select the PlayerSpriteSheet.png that you downloaded above and use it as a texture for your
new material. Select (transparent-diffuse) as the shader for your material.
Now in your player object's mesh renderer, select your PlayerMaterial in the materials tab. You should
now see what is displayed in the image on the next page:
接下来 ,为我们的角色(即平面)指定一个材质,你可能已发现,unity3d在导入fbx文件时,会自动创建一个材质,在此将自动创建的材质删除并手动创建一个新的材质赋予角色,将此材质命名为"layerMaterial",将其shader指定为transparent-diffuse,并指定其贴图为PlayerSpriteSheet.png。
Okay our player is being rendered onto our plane! Now let's make sure he's tiled correctly. Select your
PlayerMaterial and set your X tiling to -0.2 and your Y tiling to -0.25. We are going to animate our
character by changing the tiling of the character dynamically over time! I set the Y tiling to -0.25 for
mathematical reasons, in the next tutorial we shall cover animation and if this is not set to a negative
value the animation wont run properly because of the way I have set up calculating which animation to
play. And set the X tiling to -0.2, I have no idea why it's a negative value I must have had a reason a
while ago when I wrote the animation code but the code likes it to be that way and I'm going to trust it.
Next add to your player (component – physics – rigidbody) and (component – physics – capsule
collider) the capsule collider adds a collision object to our player, this collision object will collide with
other collision objects in our world. The rigidbody gives our player a physics based movement to our
capsule collider, this is allows our collider to move around, push and interact with other objects in our
game world.
现在我们的角色已经出现在场景中平面物体上,选择角色材质,将贴图的XYtiling分别设置为-0.2和-0.25
|
|