• 大小: 3KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-06-15
  • 语言: C#
  • 标签: Unity  

资源简介

基于Unity引擎编写的适合在3D场景中内画平滑线的脚本,无需修改可直接使用,仅供学习参考。

资源截图

代码片段和文件信息

using System;
using System.Collections;
using System.Reflection;
using UnityEngine;

public class example : MonoBehaviour {
public Transform[] Target = new Transform[5];
public Vector3[] TargetV3 = new Vector3[5];
private LineRenderer lineRenderer;
private int SmoothSens = 20;
private int Targetlenght = 0;

void Start(){
Targetlenght = Target.Length;
}

    void Update() {
Targetlenght = Target.Length;
for (int i = 0; i < Targetlenght; i++)
{
TargetV3[i] = Target[i].position;
}
DrawPathHelper(TargetV3Color.red);
}

public void DrawPathHelper(Vector3[] path Color color){
Targetlenght = Target.Length;
SmoothSens = 20;

lineRenderer = GetComponent();
lineRenderer.SetVertexCount(SmoothSens*Targetlenght+1);
lineRenderer.SetWidth(0.1f 0.1f);

Vector3[] vector3s = PathControlPointGenerator(path);
Vector3 prevPt = Interp(vector3s0);
Gizmos.color=color;
int SmoothAmount = path.Length*SmoothSens;
for (int i = 1; i <= SmoothAmount; i++) {
float pm = (float) i / SmoothAmount;
Vector3 currPt = Interp(vector3spm);
lineRenderer.SetPosition(i-1 currPt);
lineRenderer.SetPosition(i prevPt);

prevPt = currPt;
}
}

public Vector3[] PathControlPointGenerator(Vector3[] path){
Vector3[] suppliedPath;
Vector3[] vector3s;

//create and store path points:
suppliedPath = path;

//populate calculate path;
int offset = 2;

评论

共有 条评论