移除 TrailRenderer 中的所有点。这对于从新位置重新开始拖尾很有用。
using UnityEngine; using System.Collections;
[RequireComponent(typeof(TrailRenderer))] public class ExampleClass : MonoBehaviour { private TrailRenderer tr;
void Start() { tr = GetComponent<TrailRenderer>(); tr.material = new Material(Shader.Find("Sprites/Default")); }
void Update() { tr.transform.position = new Vector3(Mathf.Sin(Time.time * 1.51f) * 7.0f, Mathf.Cos(Time.time * 1.27f) * 4.0f, 0.0f); }
void OnGUI() { if (GUI.Button(new Rect(25, 25, 200, 30), "Clear")) tr.Clear(); } }