c# - 如何停止画线1秒然后继续统一?
问题描述
我有一段代码在头部后面画线,我想在每 200 点线后停止画线。头部应该在没有线条的情况下继续走 1 秒钟,然后在头部后面再次画出 200 点的线条。
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class Tail : MonoBehaviour
{
public float pointSpacing = .1f;
public Transform snakehead;
List<Vector2> points;
LineRenderer line;
void Start()
{
line = GetComponent<LineRenderer>();
points = new List<Vector2>();
SetPoint();
}
void Update()
{
if (Vector3.Distance(points.Last(), snakehead.position) > pointSpacing)
SetPoint();
}
void SetPoint() {
points.Add (snakehead.position);
line.positionCount = points.Count;
line.SetPosition(points.Count - 1, snakehead.position);
}
}
解决方案
为此,您可以使用 Unity 中表示的 TrailRenderer - https://docs.unity3d.com/ru/2019.4/Manual/class-TrailRenderer.html
推荐阅读
- google-identity - Google One Tap 无法在移动 Chrome 上运行
- c++ - 类用容器管理其他类的对象
- python - 在python中查找数组的逆
- azure - Azure Blob 存储生命周期管理 - 筛选文件夹
- ios - tableview 有时不加载,有没有刷新它?
- visual-studio-code - VS Code 无法识别 TI C2000 编译器
- c++ - 在我的 cmake 项目中将 freetype2 编译为依赖项
- java - 为什么将子类输入为其父级定义的 TreeMap 时会出现错误?
- qemu - 如果寄存器状态相同,指令的执行顺序是否重要?
- android - 我应该如何实现我的 AsyncTask 类?