Unity3D官方教程——Survival Shooter学习记录

unity 官方教程Survival Shooter 学习笔记

 

1.准备工作

新建项目并导入官方商店的Survival Shooter资源

在Assets下新建文件夹_Scence并在新文件夹内保存当前新场景命名为Main


2.背景和背景音乐设置

在Prefabs文件夹下拖入预制件Environment和Lights,并把系统自带的Direction Light删除。记得拖入的两个新预制件都要reset。

 

我们可以看到游戏环境里的地板是不平的,为了之后游戏的方便,我们创建一个平面(Hierarchy→Create→3D Object→Qaud)并命名为Floor,reset并设置Rotation为(90,0,0)Scale为(100,100,1)使平行于地面并覆盖。我们只需要平面的碰撞器特性,不需要看见它,所以删掉Floor的Mesh Renderer组件。将Floor的Layer选择为Floor属性(非常重要,不然之后人物不转动)

 

接下来新建空对象(Shift+Ctrl+N)命名为BackgroundMusic并reset,添加Audio Source组件,在Audio Clip里选择Background Music,勾选Loop循环,并取消Play On Awake,将音量Volume设为0.1。保存场景(Ctrl+S)。

 

 

3.添加游戏角色

将已在游戏包内做好的主角模型Player拖入到Hierarchy下并reset,将角色的Tag设置为Player(Layer决定摄像机的射线投射&渲染对象和灯光的 特定照射,Tag是 为了可以在脚本内使用(GameObject.FindWithTag())语句来快速搜索相关对象)

 

接下来做一个动画管理器,选定Assets新建文件夹Animation,在Animation下create新建一个Animator Controller命名为PlayerAC。将新建的PlayerAC拖入Hierarchy下的Player,于是Player多了一个动画管理器组件。

 

双击新建的PlayAC,我们可以在左边看到Animator界面。单机Models下的Player,将三个动画文件一个一个拖入到Animator,拖入后右键点击Idle选择Set Layer As Default State使动画空闲状态为默认动画(点击后所选择的动画变为橙色)。

 

接下来非常重要,在Animator窗口里点击Parameters选项卡,点击+号新建状态。

先点击+选择Bool,命名为IsWalking,表示判断角色是否在动。再次点击+选择Trigger,命名为Die,判断角色是否死亡。注意一定要拼写正确,大小写都对上,不然之后脚本里没法调用。

然后我们要让管理器知道什么状态下播放什么动画。先右键点击橙色的Idle,选择Make Transition,可以看到鼠标拖出了一条线,将鼠标点击灰色的Move,可以看到Idel有个箭头指向了Move,单击这个箭头,可以看到箭头变成蓝色了,在右面的Inspector选项卡里点击Conditions下面的加号,会出现IsWalking,选择true。表示当运动时由空闲动画转为运动动画。

同样的,点击Move后右键拉箭头指向Idle,之后单击箭头,在conditions下面选择IsWalking,选择false。表示角色不动了则由运动转为空闲动画。

角色死亡状态是在任何状态下死亡都调用死亡动画,所以单击Any State拉箭头指向Death,单击箭头,conditions选择Die。

 

为了主角可运动和被触发,我们添加Rigidbody和Capsule Collider组件。Rigidbody下我们不希望运动有阻力,所以在Drag和Angular Drag上都填inf,表示infinity。之后在Constraints下,将Freeze Position的Y和Freeze Rotation的X&Z勾选,表示我们不希望角色在这些方向上运动。

Capsule Conllider上我们将中心Center设为(0.2,0.6,0),Height设为1.2以符合高度。

最后我们为角色添加Audio Source组件,Audio Clip选择为Player Hurt,Player On Awake和Loop我们都取消勾选。

 

现在我们让人物动起来,打开Scripts文件夹下的PlayerMovement脚本并编辑

 

保存后回到unity,测试。发现角色可以移动了,但不能转向。打开Aimator,单击两个状

Zombie Raid is a thrilling top-down shooter survival game set in a post-apocalyptic world overrun by zombies. The game features fast-paced action, challenging gameplay, and a variety of weapons and power-ups to help you survive. As a survivor, your goal is to protect your base from the endless waves of zombies. You'll need to use your wits and quick reflexes to stay alive and fend off the undead hordes. The game features a variety of weapons, from pistols and shotguns to assault rifles and rocket launchers, to help you take down the zombies. In addition to weapons, you can also collect power-ups like health kits, ammo crates, and special abilities to help you survive. These power-ups can be found scattered throughout the game world, so be sure to explore and scavenge as much as possible. Zombie Raid also features a variety of enemies, from slow-moving zombies to fast and agile ones, as well as bosses that require strategy and skill to defeat. You'll need to adapt to each new wave of enemies and use different tactics to survive. The game also features multiple levels, each with its own unique challenges and objectives. As you progress through the game, you'll unlock new weapons and abilities, making it easier to take on the hordes of zombies. Overall, Zombie Raid is a fun and exciting top-down shooter survival game that will keep you on the edge of your seat. With its challenging gameplay, variety of weapons and power-ups, and endless waves of zombies, it's a game that's sure to keep you entertained for hours on end.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值