How would I scale just the borders of a sprite with C#?

I am spawning in a sliced sprite with C# and that works just fine. (I’m using it as a UI element) The only thing is the left and right borders of the sliced sprite are a bit squished as I scale the sprite vertically as they are curved the entire way. I’m wondering if I can make a scale change to just the left and right borders of the sprite.

My only requirement is this left and right border width change needs to be done completely with code.

When you say you are “spawning in a sliced sprite” you mean the sprite is already 9-sliced on the Sprite Editor? (Unity - Manual: 9-slicing Sprites)

If you already did and the left and right are squished, you may need to tune the border values.

If with “sliced sprite” you mean that several sprites are contained into a single image and you want to do everything with code, you will have to 9-slice yourself. For example:

  1. Extract the sprite from your image file
  2. Divide the sprite Texture into 9 RenderTextures using Graphics.CopyTexture
  3. Resize each of them with a shader or using Graphics.Blit
  4. Copy the 9 slices into a new single RenderTexture using Graphics.CopyTexture

I hope its helpful. If not, can you provide some more information?