Making a repeating chain of Sprites

I want a make a dynamic chain of sprites, where I take one sprite and unity repeats it between two points (represented by the vector3 positions of two empties). Here’s a gif I created in Blender which represents the behaviour I want:

Gfycat.com Link

The ‘LineRenderer’ component can be used to make a repeating texture like the one you described, and it always faces the camera. Note that its Material must be a Particle Shader, which means the texture may have transparency where it should be opaque.

  • Add a LineRenderer to the first GameObject
  • set its UseWorldSpace to true
  • Create a new Material
  • Set its Shader to Particles/Additive (LineRenderers only work with Particle shaders)
  • Set your texture (i.e. chain link sprite) as its Particle Texture
  • Set this Material as the LineRenderer’s first Material
  • Add the new SpriteLine script below to the GameObject with the LineRenderer
  • Set the second GameObject as its ConnectTo

And you’re good to go!

If you want the line to overlap the ConnectTo point instead of stopping before it, change Mathf.FloorToInt to Mathf.CeilToInt.

‘Sprite Scale’ is how long each sprite should be. If you want to change the width of the sprite, change both the ‘Start Width’ and ‘End Width’ of the LineRenderer’s ‘Parameters’ block.

SpriteLine.cs

using UnityEngine;

public class SpriteLine : MonoBehaviour
{
    public Transform ConnectTo;
    public bool UpdateChain = true;
    public float spriteScale = 1f;

    void Update()
    {
        LineRenderer renderer = GetComponent<LineRenderer>();
        if (renderer != null)
        {
            if (ConnectTo != null)
            {
                if (UpdateChain)
                {
                    int spriteCount = Mathf.FloorToInt(Vector3.Distance(ConnectTo.position, transform.position) / spriteScale);

                    Vector3[] positions = new Vector3[] {
                    transform.position,
                    (ConnectTo.position - transform.position).normalized * spriteScale * spriteCount
                };

                    renderer.SetVertexCount(positions.Length);
                    renderer.SetPositions(positions);

                    if (renderer.material != null)
                        renderer.material.mainTextureScale = new Vector2(spriteScale * spriteCount, 1);
                    else
                        Debug.LogError(name + "'s Line Renderer has no material!");
                }
            }
            else
            {
                renderer.SetVertexCount(0);
            }
        }
        else
        {
            Debug.Log(name + " has no LineRenderer component!");
        }
    }
}