unity sprite render sliced set width at runtime code example
Example 1: how to change spriterenderer size from c# script
void Start() {
spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer.drawMode = SpriteDrawMode.Tiled;
spriteRenderer.size = new Vector2(5,1);
}
Example 2: how to change spriterenderer size from c# script
sprRend.size = new Vector2(3, 1);