- Home /
Question by
stay.metal · Sep 01, 2014 at 08:34 AM ·
touchtrailrendererfinger
how can i create a finger trail
Hey whats up guys how can i create a Trailrenderer based on my touch? kind of like fruit ninja when they drag their finger around it leaves a trail.
here is my code its kind of what im looking for but not exactly, the trail is dealyed i want it to snap to my position.
using UnityEngine;
using System.Collections;
public class TouchMove : MonoBehaviour {
public float smooth = 100;
public float speed = 0.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0) {
// The screen has been touched so store the touch
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
Vector2 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y,10));
transform.position = Vector3.Lerp(transform.position, touchPosition, Time.deltaTime * smooth );
}
}
}
}
Comment
Answer by Vitor_r · Sep 01, 2014 at 02:09 PM
You can use TrailRenderer on a GameObject and while you move your finger change the position of the Object to the touch position. When are no touchs just fade it away.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162012im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Unity2D Android] Multitouch won't work 1 Answer
Mobile game Player follow finger input problem (C#) 2 Answers
object falow finger problem ? 4 Answers