补充:在本人开unity之后会出现这样的报错
实际上这个报错的源头是安装了 Proxifier 软件导致网络错误
创建敌人行走的道路
随心选择一条道路,最好从坐标零点开始,将路径上的cube删除,再用新的cube将路连接到一起,用不同的材质加以区分
我们将新建的cube放进一个新的文件夹中方便管理,需要注意的是,新建的gameobject最好重置后再放入cube,后面的坐标是根据这个gameobject的相对位置,未重置后续的工作可能会比较麻烦
起点和终点我分别放了两个材质不同的cube,以便后面调用
玩家视野的移动
因为地图较大,于是我们做一个玩家能控制摄像机前后左右,放大缩小的功能
在层级中选择main camera,将角度位置调至满意的位置
接下来为main camera制作组件,点击maincamera,在检查器中的最下面新建组件ViewController,在项目中新建文件夹Scripts方便管理脚本组件,将ViewController拖入其中,双击开始编辑
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ViewControler : MonoBehaviour
{
public float speed = 1;
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Translate(new Vector3(h, 0, v) *Time.deltaTime*speed);
}
}
因为之前没接触过c#,所以还在一个个单词理解其作用
由于现在的x,z轴还是以摄像机的本身坐标为准,所以应该在transform中添加space.world
这样摄像机的移动将会以世界坐标为准
我们也想将y轴交给鼠标滚轮来管理,所以添加鼠标滚轮的变量mouse,并将y轴由0改为mouse
这时我们运行发现,鼠标的数值改变太小,不能和x,z轴共用一个速度,要重新定义一个速度变量
当然也可以重新transform一个
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ViewControler : MonoBehaviour
{
public float speed = 1;
public float mousespeed = 60;
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
float mouse = Input.GetAxis("Mouse ScrollWheel");
transform.Translate(new Vector3(h*speed, mouse*mousespeed, v*speed) *Time.deltaTime*speed ,Space.World);
}
}
之前不小心删掉了地板这里添加了地板,且逐个更正了地图上的每一个方块的坐标使之美观且易于操作,下面图即为现阶段成品