窗口界面以及菜单
Scene
场景编辑窗口,用于对场景的设计以及物体的处理。

这个时候按住鼠标右键可以对场景查看,全景查看。按下w,s可以对镜头远近调节,a,d可以左右位移,如果仅仅是鼠标左右移动那就仅仅只能旋转而已。
Game
游戏运行窗口。




Hierarchy
场景物体,列表窗口。

在unity里面列表里面所有的场景都会以列表的形式展示在Hierarchy里面。双击就可以定位到物体处。同时也可以搜索,没有搜索到,不匹配的物体都会是灰色,匹配到的才会是彩色。
Project
项目资源,列表窗口。

游戏的资源都会显示在ASssets里面,和window的文件系统的一样的,但是unity会自动生成每一个文件的mets的后缀文件,如果想要移动资源,那就需要在unity里面移动,这条mets文件才会跟随移动,上方的Favorites可以选择特定物体。
Inspector
属性编辑,列表窗口。
点击每一个物体都会有对应的属性,比如transform就保存了位置信息。
File菜单


点击Player Setting就是到对于一些平台属性的修改。

Edit编辑菜单



File是对于整个项目的打包发布等等的设置,而Edit是对编辑器的一些设置,而下面要提到的Assert是对项目资源的一些管理。
Assert菜单
首先下拉第一个create:

添加文件,添加脚本,添加材质资源,添加动画,以及GUI和字体等等。
GameObject菜单
这个菜单就是对Hierarchy的管理了。选中一个物体,点击move to view就可以直接跳到当前物体,也就是camera会到这个物体的正前方。gameobject游戏物体,场景中所有的东西都是游戏物体,包括了游戏场景,都是物体。
坐标系
常规下坐标系一般是xyz轴:





把物体拖上去之后位置没有变化,但是相对的坐标系改变了。

Roll A Ball
游戏环境
首先是创建工程,unity5一开始就自带了一个默认场景,上面提到了,所有的资源包括了场景物体等等都是保存在了Assert这个资源下。首先是创建一个游戏环境,直接搭就好了,创建五个cube,按照比例拉长排列就好,为了管理方便,最后·把他们放在ground下面统一管理。
物体创建
添加一个球体然后调一下大小即可。

添加脚本
添加脚本这个操作很简单。要做的处理是,首先需要得到这个组件的刚体,然后控制上下移动。初始化的C#脚本是这样的:


如果想通过键盘移动,可以使用Input这个类。


相机跟随
完成了移动,那么就还有相机跟随了,很明显,现在这个相机视角,我不服。首先在scene找到一个比较好的视野,然后点击GameObject-Align with view把相机定位到当前视野,之后就用代码来调整了。相机同步无非就是相机和物体的偏移量不变而已,也就是相机和物体的相对位置保持不变。
首先定义一个Transform的变量,用来存储小球的位移信息,由于是public变量,可以直接可视化的把小球的transform直接拖过来就好了。start先得到偏移量,然后update进行同步过程即可。
控制移动范围
加四个小墙就好了。
添加食物
首先创建一个小正方形,然后把它放到Assert一个文件夹下,也就是把它做成一个预制体,通俗点说就是模型,往后只要是从这个模型赋值出来的物体,那么只要模型改变,全部都会变。使得食物旋转,一样的现在模型上创建脚本,如果是一个一个改那很麻烦,所以模型上改,transform有一个rotate方法。

update方法一秒大概调用60次。
碰撞检测
如果移动小球,那么如果碰到了食物是会被挡住的。首先就是碰撞检测的问题,unity的API已经给出了碰撞的函数,朱啊哟讨论的有两种,一种是直接的碰撞检测,




分数啊什么的很简单。
显示分数以及胜利
在右键UI添加text,然后再player脚本里面获得者两个对象,由于胜利了这个是要最后赢了才全部出现,所以需要先取消激活,也就是不勾上右上角:
代码激活,上面写了,setActive即可。前面的风格和后面的风格差异有点大,一个是2018一个是5.5,因为5.5不能用GitHub for unity,所以把5.5的版本移植到2018再提交到GitHub,emmm。

GitHub
最后附上GitHub代码:https://github.com/GreenArrow2017/Roll-A-Ball