路点
塔防游戏的敌人不需要自动寻路,只需要沿着一条预设的路线前进即可。
1、创建路点
1、创建路点的tag
2、为路点创建脚本PathNode.cs,代码为
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pathnode : MonoBehaviour
{
// Start is called before the first frame update
public Pathnode m_nextNode = null; //后一个结点
public Pathnode m_preNode = null; //前一个结点
public void SetNext(Pathnode node)
{
if(m_nextNode != null)
{
m_preNode = null;
}
m_nextNode = node;
node.m_preNode = this;
}
private void OnDrawGizmos()
{
//Node.tif在Gizmos目录下
Gizmos.DrawIcon(this.transform.position, "Node.tif");
}
}
2、扩展界面
1、创建PathTool.cs脚本。这是用来创建一个自定义的菜单栏,帮助我们设置路点。存放在Editor目录下。PathTool.cs的代码为:
using System.Collections;
using System