How to create swipe trails of buttons in unity?

112077-28504164-981956698633117-2066968694-o.pngI want to create a swipe trails like in the attached picture from the buttons.
How to do this?
Please suggest. Thanks

You can probably get away with mapping your touch locations over time to a LineRenderer Component’s vertices. How far along in the problem are you? You can start by just having an object follow the touch positions on screen.

The question inspired me, so I threw together this script that uses the mouse position to draw a trail in 3D, but I think it is easy to adapt to touch controls:

using System.Collections.Generic;
using UnityEngine;

public class CursorTrail : MonoBehaviour {

    [SerializeField]
    private LineRenderer trailPrefab = null;

    [SerializeField]
    private float clearSpeed = 1;

    [SerializeField]
    private float distanceFromCamera = 1;

    private LineRenderer currentTrail;
    private List<Vector3> points = new List<Vector3>();

    private void Update () {
        if (Input.GetMouseButtonDown(0)) {
            DestroyCurrentTrail();
            CreateCurrentTrail();
            AddPoint();
        }

        if (Input.GetMouseButton(0)) { AddPoint(); }

        UpdateTrailPoints();

        ClearTrailPoints();
    }

    private void DestroyCurrentTrail () {
        if (currentTrail != null) {
            Destroy(currentTrail.gameObject);
            currentTrail = null;
            points.Clear();
        }
    }

    private void CreateCurrentTrail () {
        currentTrail = Instantiate(trailPrefab);
        currentTrail.transform.SetParent(transform, true);
    }

    private void AddPoint () {
        Vector3 mousePosition = Input.mousePosition;
        points.Add(Camera.main.ViewportToWorldPoint(new Vector3(mousePosition.x / Screen.width, mousePosition.y / Screen.height, distanceFromCamera)));
    }

    private void UpdateTrailPoints () {
        if (currentTrail != null && points.Count > 1) {
            currentTrail.positionCount = points.Count;
            currentTrail.SetPositions(points.ToArray());
        }
        else { DestroyCurrentTrail(); }
    }

    private void ClearTrailPoints () {
        float clearDistance = Time.deltaTime * clearSpeed;
        while (points.Count > 1 && clearDistance > 0) {
            float distance = (points[1] - points[0]).magnitude;
            if (clearDistance > distance) { points.RemoveAt(0); }
            else { points[0] = Vector3.Lerp(points[0], points[1], clearDistance / distance); }
            clearDistance -= distance;
        }
    }

}

Result:
112127-capture.png

Add this script to any GameObject in the scene, and assign a prefab to trailPrefabthat has a LineRenderer on it. Setting a transparent alpha for the beginning of the LineRenderer and 6 corner vertices, 8 cap vertices will give you a nice rounded trail.

clearSpeed controls the length of line cleared up per second (that’s why it is speed). Setting it to about 25 leaves you enough time to see the trail, but it also gets cleared up relatively fast.

how to create trail render visible or working only particular place of the camera?