- Home /
Question by
vlad_gaujaneanu · Jul 22, 2016 at 03:00 PM ·
line rendererline drawing
Line renderer erase problem
Hello, I am trying to use line renderer to draw some lines on an object, then move the object outside of the screen.
Basically, after the object collider detects the mouse it sets an entry point, and when the mouse leaves the collider it sets an exit point and draws a line between those two. Each line is an empty GameObject with a Line Renderer component attached, which I make child to the main object.
My problem is, whenever I move the object, it leaves some sort of trail behind the line which disappears if I pause the game, then hit play again. Does anyone have any idea how to prevent that?
Here is my code:
void OnTriggerEnter2D (Collider2D other)
{
enterPoint = mousePos;
enterPoint.z = 0;
points.Add (enterPoint);
}
void OnTriggerExit2D(Collider2D other)
{
exitPoint = mousePos;
exitPoint.z = 0;
points.Add (exitPoint);
GameObject obj = new GameObject ();
GameObject instance = Instantiate (obj, transform.position, Quaternion.identity) as GameObject;
Destroy (obj);
instance.transform.SetParent (transform);
instance.name = "Cut";
linerenderer = instance.AddComponent<LineRenderer> ();
linerenderer.useWorldSpace = false;
linerenderer.SetWidth (0.15f, 0.15f);
linerenderer.SetVertexCount (2);
linerenderer.SetPosition (0, enterPoint);
linerenderer.SetPosition (1, exitPoint);
}
Comment
Your answer
Follow this Question
Related Questions
attach drawing line using (LineRenderer) to moving background 0 Answers
LineRenderer fade out 0 Answers