Duplicate the WayPoint game object twice and arrange the waypoints in a triangle
shape (position quite far apart).
重复制作两个路径点游戏对象并且把它们排成一个三角形(距离远一些)
Check that the waypoints are visible to each other by firstly clicking on any waypoint then selecting Update Waypoint from the context menu of the AutoWayPoint script (the rightmost button on the component in the Inspector View). A green line will be drawn between visible waypoints, a red line for those which don’t have a clear line of sight.
Add the AIAnimation script to the robot. This controls the animation of our robot (when to***n, when to aim etc). This communicates with the AI script to find out what the AI script is currently doing, e.g. are we***nning, shooting etc.It then crossfades the animations to provide a smooth transition.
Now we need to make the robot controller object a little larger so that he doesn’t intersect with the ground. This is because the character controller which is used to prevent the enemy from moving through walls is using a capsule to represent the AI. We need to make this capsule a little larger to match the actual graphics, this way he will not intersect with the ground anymore.
Try making the height and radius values smaller and larger to see the difference.
试着将高度和半径值改的稍大一些看看有什么不同。
Now we need to give the robot the ability to fire his gun. The robot is continuously moving and animating. When he shoots his gun we play an animation on the hands and the graphical gun then spawn the rocket from transform relative to the robot. This transform does not animate, it is simply placed approximately at the point where the gun will be when the shoot animation fires the rocket.
Make a prefab of this robot, call it Robot. This will allow you to create more enemies easily.
制造一个机器人预制物体,调用它,这将允许你建立更多的敌人。
Play the game and check that the robot fires at you.
运行游戏并且检查那个朝你开火的机器人。
Although you can shoot the robot, it is not configured to take damage, we’ll remedy
this in the next section.
尽管你能朝机器人射击,但它没有配置获得伤害,在下一节中我们将补救这些。
Robot Damage 机器人伤害
Attach the CharacterDamage script to the Robot prefab.
附着CharacterDamage脚本到机器人预制物体上。
Play the game, shoot the robot with the machine gun and he should disappear.
运行游戏,用机枪朝机器人射击并且它会消失。
Ragdolls 布偶
Ragdolls emulate a natural skeletal bone s***cture, this will allow our robot to fall naturally when killed. This section will show how to setup a ragdoll.
Create a cube (resize if necessary), this will be used as a platform for our robot. Drag in the robot to the Scene View so that it is positioned above the cube.
Remove the animation component. This is important otherwise the animations will interfere with the physics.
删除动画组件,这一点很重要,否则动画在物理上将被干扰。
Now use the ragdoll wizard: Game object >Create Other >Ragdoll.
现在使用布偶向导:Game object >Create Other >Ragdoll
A dialog box appears, now we have to assign all the bones to the correct slots in the wizard. We assign the bones by dragging the values from the Robot in the Hierarchy View onto the correct place in the dialog box. Expand the Robot gameobject in the Hierarchy View if necessary to reveal this.
Open the original scene (no need to save the current scene), select the robot from the Hierarchy View and in the Character Damage inspector, drag in the RobotRagdoll prefab to the Dead Replacement.
Play the game, shoot the robot and it should now fall down when shot.
运行游戏,朝机器人射击当射中时可以看到机器人会倒下
You may want to tweak the mass of the robot to improve the look & feel of the ragdoll. You can do this in the ragdoll wizard, by changing the mass property. This is especially important in explosion forces where the robot is thrown into the air.
Drag machineGunSingleShotLoopable onto the MachineGun gameobject.
拖拽machineGunSingleShotLoopable声音文件到机枪游戏对象上
Turn off Play on Awake.
关闭Play on Awake
Rocket Launcher 火箭发射器
We want to attach the sound source of the rocket to the rocket so that the audio levels reduces as it flies away.
我们想附加一个火箭弹声音源到火箭弹上,以便随着它的飞行,声音的大小也在减弱。
Select the Rocket prefab.
选择火箭弹预制物体
Add an Audio Source component to the prefab.
增加一个声音源组件到预制物体上
Drag the RocketLauncherFire audio source to the Audio Clip property of the Audio Source.
拖拽RocketLauncherFire声音文件到声音源的Audio Clip属性上。
Adjust the Rolloff Factor so that the sound fades out faster (0.5 might be ok).
调整Rolloff Factor以便声音衰减的更快(可能0.5秒吧)
GUI 图形用户界面
The GUI (Graphical User Interface) is responsible for giving feedback to the player on the current game status. Typical GUI elements include; number of bullets left, health, mission objectives etc.
Add an Audio Source component to the FPS player (no need to do anything else).
增加一个声音源组件到FPS玩家(不需要做任何事情)
Lights for moving objects 移动物体的亮度
The scene in our game is lightmapped, however the characters and rigidbodies can not use this lightmap since they are moving. Thus, we need to setup some lights which only affect those objects and look similar to the lighting of the lightmap. For this purpose we use the lights culling mask.
Now select the directional light again and turn off Lightmapped.
现在再次选择方向光线并且关闭灯光贴图。
Select mainLevelMesh, change the Layer property to Lightmapped. Apply this change to all child objects when prompted.
选择mainLevelMesh,改变层属性为灯光贴图,当出现提示时应用这个改变到所有的子对象上。
The end of the beginning... 这只是个开始的结束
This completes our FPS tutorial series. Many key lessons for game development have been presented and will apply to other styles of games: not only FPSstyle games. We hope that you have learned the fundamentals of game creation and are now motivated to design your own novel games with Unity.