2

I have piece of code that draws line behind the head and I want to stop drawing after every 200 points of line. Head should go further without line for 1 second and then draw again 200 points of line behind the head.

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);
    }
}


salmon
  • 21
  • 5

1 Answers1

1

For this, you could use TrailRenderer that represented in Unity - https://docs.unity3d.com/ru/2019.4/Manual/class-TrailRenderer.html

OnionFan
  • 479
  • 3
  • 10