首页 > 解决方案 > 如何停止画线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);
    }
}


标签: c#unity3dwait2d-gamespause

解决方案


为此,您可以使用 Unity 中表示的 TrailRenderer - https://docs.unity3d.com/ru/2019.4/Manual/class-TrailRenderer.html


推荐阅读