How to draw a trail after a swipe movement in Unity

I am going to show you how to draw a swipe movement in Unity.

The final effect will be like this:swipe preview

Here is the video showing how to do it:

And here is the script:

using UnityEngine;
using System.Collections;</code>

public class CursorBehavior : MonoBehaviour {

private bool touched;

// Use this for initialization
void Start () {

touched = false;

//make it desappear
GetComponent<MeshRenderer>().enabled = false;
}

// Update is called once per frame
void Update () {

//when screen touched -&gt; update cursor position

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetMouseButtonDown(0))
{
touched = true;
} else if(Input.GetMouseButtonUp(0))
{
touched = false;

} else
{
if(touched == true)
transform.position = ray.GetPoint(2);
}
}
}

Leave a comment