Search code examples
c#unity-game-engineanimationgraphicsmask

How To Animate Line Renderer Tiled Texture In Unity


I would like to reproduce the draw line effect you see in hearthstone where a line is drawn and the tiled texture of the line animates along the path.

Here is a video reference: https://youtu.be/68usg4ELkYI

I have the draw line from point to point working and I know how to set a tiled texture. My question is how do you animate the texture so it slides forward and fades.

For reference here is my code for my drawline:

[SerializeField]
LineRenderer _lineRenderer;
private void drawLineFromCardToCursor()
{
    var mousePos = Input.mousePosition;
    mousePos.z = 10.35f; // Distance from camera to world
    Vector3 worldPoint = Camera.main.ScreenToWorldPoint(mousePos);
    // Must move it forward by 1 so it appears in front of screens
    worldPoint.z = -0.001f;
    _lineRenderer.SetPosition(0, start);
    _lineRenderer.SetPosition(1, end);
}

And here is my tiling setup for my line renderer:

enter image description here

Please advise if you know how to make the tiling animate forward (and bonus if it includes fading in and out at the ends).

Thank you.


Solution

  • You can set Texture Mode to Tile.

    And then offset the texture:

    lineRenderer.material.SetTextureOffset("_MainTex", Vector2.right * Time.time);