2D Game Kit在unity的使用

本文参考:

如何制作游戏?【不需要编程 __】新手30分钟 学会制作2D游戏!_ 如何制作游戏 _ unity教学 _ 制作游戏 _ 2d游戏_哔哩哔哩_bilibili

1、下载2d game kit

新建一个unity工程,进入该工程后,在Window -> Asset Store中搜索 2d game kit。

然后下载导入到Unity中。

此时会报错,报错信息类似如下:

 Assets\2DGamekit\Utilities\Editor\RuleTileEditor.cs(69,10): error CS0433: The type 'RuleTile' exists in both 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Unity.2D.Tilemap.Extras, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' 

这是因为在导入的2d game kit和使用Unity 2D创建的项目中出现了相同的类名RuleTile。

此时使用对2D Game Kit中重名的文件进行重构。

具体参考:Unity 导入项目报错: error CS0433: The type ‘RuleTile‘ exists in both ‘Assembly-CSharp, Version=0.0.0.0,..._the type 'jsonmapper' exists in both 'assembly-csh-CSDN博客

2、 启动第一个demo

(1)在Kit Tools下选择Create New Scene

(2)点击Create后,就会自动导入Scene如下图所示:

点击启动,就可以运行Game了,运行用到的按键罗列如下:

空格:跳起来

S:蹲下来

O:发射子弹

K:用刀横扫千军

3、设计场景(scene)

(3.1)必备知识

(3.1.1)打开scene light

否则场景下会非常昏暗。

(3.1.2)移动场景

有时候scene是非常长的,此时设计时需要移动场景

可以Alt+鼠标左键 进行拖动,或者鼠标右键进行拖动。

(3.1.3)移动玩家

有时候场景设计了很多的元素,每次测试时不可能让玩家从头开始玩,此时可以将玩家移动到新设计的场景中,测试新设计的场景即可。

选择左上角的Move Tool,然后框选玩家 拖动到指定的位置。

(3.2)选择瓷盘托盘

位置:Window -> Tile Palette,

有两种类型可供选择:

使用时,鼠标左键选择图片,然后鼠标在Scene中移动时就会拖着那个图片了,在scene中鼠标左键拖拽即可添加该图片。如果想要删除图片,则Shift按住+鼠标左键拖拽即可实现删除。

我简单地创建了如下的示例:

(3.3)选择场景元素

位置:Assets -> 2DGamekit -> Art -> Sprites -> Environment

我简单地创建了如下的示例:

(3.4)添加陷阱

场景元素位置:Assets -> 2DGamekit -> Prefabs -> Environment

Acid是毒液:当玩家掉下去的话就会死掉。

Spikes是尖刺:当玩家碰到之后就会扣血。

(3.5)添加移动平台

位置:Assets -> 2DGamekit -> Prefabs -> Interactables

添加后可以设置移动的距离以及方向:

添加完毕之后的测试效果:

 

接下来,添加自定义多Node的移动平台。

在组件中,选择"Add Node"就可以添加多段的移动路径了,选择"Preview position"可以预览移动的路径。

在该组件中,"Is Moving At Start"是未被勾选的,这就意味着该移动平台一开始并不会移动,需要另一个组件触发一下。

 选择SingleUseSwitch,然后在该组件的On Enter()事件处理中,添加Moving Platform对象,并为该对象指定StartMoving函数。

(3.6)添加可摧毁的墙

位置:Assets -> 2DGamekit -> Prefabs -> Interactables,选择DestructibleWall

在右侧的属性栏中,设置"Starting Health"的值决定需要击打的次数。

(3.7)添加门(可关闭和打开)

位置:Assets -> 2DGamekit -> Prefabs -> Interactables,选择Door,但是这个门是不会自动打开或者关闭的。

需要添加PressurePad来控制的门的打开或关闭,对PressurePad的操作如下:

首先,选中PressurePad,在Boxes的On Pressed()中添加新的事件。

其次,将Door对象拖入新增的事件的对象参数中,如下图所示:

接着,选择该事件的函数为Animator -> Play(string) 

 然后,输入Play的入参为DoorOpening,如上上一张图所示。

该参数对应的动画位于Assets -> 2DGamekit -> Art -> Animatiions -> AnimationClips -> Interactables下。

下面就是玩家踩中PressurePad时,门打开的场景:

(3.8)创建敌人

位于:Assets -> 2DGamekit -> Prefabs -> Enemies,有两种敌人可供挑选:

  • Chomper:这个是近战的敌人
  • Spitter:这个是远程攻击的敌人

Chomper的参数设置:

初始化的Chomper如下,青色的圆圈代表它的视野范围:

可以通过View Fov参数调节它的视野角度,只让它看到前方的物体。

通过View Distance参数可以调节视野的远近。

(3.9)可推动的box

位于:Assets -> 2DGamekit -> Prefabs -> Interactables,选择pushtableBox,

此时,在Scene有一个可以推动的box,但是并不会对敌人产生伤害。

该box会一直在敌人的上面,但是没有对敌人产生伤害。

此时需要:

1)给pushtableBox添加组件Damager脚本

2)修改offset、size的大小如下

3)hittable layers选择可伤害的对象为Enemy

(3.10)收集钥匙打开门

首先,在Assets -> 2DGamekit -> Prefabs -> Interactables下选择Door和Key,如下图所示:

 此时在游戏中,碰触Key和Door都不会有任何反应。

接着,Assets -> 2DGamekit -> Prefabs -> UIPrefabs中添加KeyCanvas到Hierarchy的UI下。运行游戏后,就会在Scene的右上角出现3个key。

然后,我们需要实现碰触Key后就收集Key的功能。

我们先看一下主角Ellen可以占有的道具,在Inventory Controller脚本下可以看到所有的道具名称。

 在Key对象下,添加Inventory Item的脚本,在脚本中进行如下配置:

 Inventory Key的名称设置为Key1,刚好对应主角可以获取的道具名称。

Layers设置为Player,表示只有玩家才能获取key

Disable On Enter勾选一下,表示key被获取就消失掉

Clip是获取一瞬间的音效

在Circle Collider 2D的脚本中,radius调整下大小。

最后,实现收集钥匙后打开门的功能。

 添加key1触发事件的对象以及行为。

(3.11)添加加血包

位置:Assets -> 2DGamekit -> Prefabs -> Interactables,选择HealthPickup。

 

只有在玩家掉血了之后,该加血包才会触发生效。

(3.12)传送门

位置:Assets -> 2DGamekit -> Prefabs -> Interactables,选择Teleporter。

然后需要通过设置告诉传送门,把谁移动到哪里。

1)在游戏刚开始的位置再添加一个传送门,这个就是目标位置。

 2)配置Teleporter的Transition Point脚本

 

(3.13)对话框

位置:Assets -> 2DGamekit -> Prefabs -> UIPrefabs,添加DialogueCanvas到Hierarchy的UI下。

 

假设让Teleporter说话,那么针对Teleporter添加Interact On Button 2D的脚本。

Layers就是只针对玩家才说话,说话的内容默认情况下不支持中文

On Enter配置事件信息,就是触发DialogueCanvas说话,函数配置为:

路漫漫其修远兮,在U3D的道路上吾将上下而求索~~

Unity 2017 2D Game Development Projects: Create three interactive and engaging 2D games with Unity 2017 Build classic arcade, shooter and platform games with Unity 2D toolset 2D games are everywhere! Timeless and popular, 2D games represent a substantial segment of the games market. The Unity engine has revolutionized the gaming industry, by making it easier for game developers to create quality games on a budget. If you are looking for a guide to create 2D games using Unity 2017, look no further. With this book, you will learn all the essentials of 2D game development by creating three epic games in a step-by-step manner throughout the course of this book. The first game will have you collecting as many cakes as possible. The second will transport you to outer space to traverse as far as possible while avoiding enemy spaceships. The last game will have you running and jumping across platforms to collect coins and other exotic items. Throughout all these three games, you will create characters, make them move, and create some enemies. And then, of course, write code to destroy them!. After showing you the necessities of creating a game, this book will then help you to porting the game to a mobile platform, and provide a path to publish it on the stores. By the end of this book, you will not only have created three complete great games, but be able to apply your knowledge to create and deploy your own games. What You Will Learn Work with Unity 2017’s new 2D workflow and create a 2D scene Set the scene with different types of backgrounds, either static or dynamically using a tileset Bring your character to life through simple animations Understand the core concepts of programming by creating basic code that controls a character and destroys an enemy Create buttons and game controls by using code snippets for input detection Develop three 2D games from genres such as classic arcade, space shooter, and platformer games Add audio and feedback and deploy your games
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值