day14 Unity特效渲染
一,粒子系统
在层级视图当中创建空白对象,然后给其添加组件Compnent—Effects—Particle System.
二,拖尾渲染
组件:TrailRenderer
三,线 性 渲 染
代码:
自动导航的描点
public LineRenderer line;
NavMeshAgent agent;
public Transform[] targets;
int index = 0;
NavMeshPath path;//保存导航路径
void Start () {
agent = GetComponent<NavMeshAgent>();
agent.SetDestination(targets[index].position);
path = new NavMeshPath();
}
// Update is called once per frame
void Update () {
if (agent.remainingDistance<=agent.stoppingDistance)
{
index++;
index %= targets.Length;
agent.SetDestination(targets[index].position);
}
DrawPath();
}
void DrawPath()
{
//判断是否能计算导航路径
bool res = agent.CalculatePath(agent.destination,path);
if (res)
{
//获取路径的拐点
Vector3[] corners= path.corners;
//设置line的顶点数
line.positionCount = corners.Length + 2;
line.SetPosition(0, transform.position);
for (int i = 0; i < corners.Length; i++)
{
line.SetPosition(i + 1, corners[i]);
}
line.SetPosition(corners.Length + 1,agent.destination);
}
}