I'm trying to create a Tiled Sprite, what am I doing wrong?

Since apparently Unity 2D still lacks tiled sprites, I’m tyring to create a class which takes a normal Sprite and tiles it using custom dimentions.

It doesn’t crash, but doesn’t yield results either: I just get an empty sprite apparently.

The transform position is correct (unaltered), I do use Apply, and the new width is multiple of the original one. Now I’m clueless about what could be the problem.

Here’s the script, can anybody help?

    using UnityEngine;
    using System.Collections;
    
    public class TiledSprite : MonoBehaviour
    {
    	public int width,height;
    
    	private SpriteRenderer renderer;
    	private Sprite originalSprite;
    
    	void Awake ()
    	{
    		renderer=GetComponent<SpriteRenderer>();
    		originalSprite=renderer.sprite;
    
    		// crea il nuovo Sprite
    
    		Texture2D target = new Texture2D(width,height);
    		int ow = originalSprite.texture.width;
    		int oh = originalSprite.texture.height;
    
    		Color32[] pixOrig = originalSprite.texture.GetPixels32();
    		Color32[] pixDest = new Color32[width*height];
    
    		int osize=ow*oh,dsize=width*height;
    		int cur=0;
    		while (cur<dsize)
    		{
    			for (int cur2=0; cur2<osize; cur2++)
    			{
    				pixDest[cur++]=pixOrig[cur2];
    			}
    		}
    
    		target.SetPixels32(pixDest);
    		target.Apply();
    
    		Sprite newSprite = Sprite.Create(target,new Rect(0,0,width,height),new Vector2(width/2,height/2));
    		renderer.sprite=newSprite;
    	}
    }

hmm do you need to do this at runtime ? because you can use the slice “grid” option in the sprite editor , once you set the sprite mode to multiple.

This is not what I’m trying to do.

I want to display a single sprite, tiled multiple times.