資源簡介
基于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? {
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;
- 上一篇:網上購物系統的設計與實現源代碼
- 下一篇:Unity Windows Speech
評論
共有 條評論