Hey guys,
i just want to ask if there is some way to create 9 slices on sprite via c# script.
Thanks
Hey guys,
i just want to ask if there is some way to create 9 slices on sprite via c# script.
Thanks
You will need to create a GameObject with a SpriteRenderer and have the SpriteRenderer use your Sprite. After that, you can change SpriteRenderer.drawMode to SpriteDrawMode.Sliced/Tiled and adjust SpriteRenderer.size to get what you need.
If you are creating a Sprite on Runtime, when using Sprite.Create to create the Sprite, you will need to ensure the border parameter is set correctly for nine-slicing.
Thank you @ChuanXin for answer. That is exactly what i need to solve my problem.
I’ve been having a Horrible time trying to get this working In Runtime without any sort of Unity Editor,
Can someone here Please give me a more constructive comment then just sorta saying “oh yeah set the draw mode and then scale it” without any actual helpful information.
there is 0 documentation on formatting Sprites for nine-slicing in Runtime via Code Only, and it’s Driving me Insane
“border parameter is set correctly for nine-slicing.” doesn’t help at all, I’ve been debugging this for 4 hours non-stop and still no decent progress, I’ve tried getting a Texture2D and creating a new Sprite using it even, with Many different border variations and I’ve had No Visible success
For context : I’m modding a game that allows for runtime script execution