I was wondering if it was possible to create a new sprite at runtime. I’m basicly trying to slice a Sprite in 2 pieces (similar to Metal Gear Rising but in 2D)
In this example, i’m creating a copy of the current object and i’m trying to create a new sprite for it’s SpriteRenderer. I’m able to create the new sprite and the new texture but when I assign them to the SpriteRenderer, it does not display anything. The result is an invisible object (since the SpriteRenderer is not diplaying). The strange part is that when I select the sprite in the SpriteRenderer component of the new object, the preview is showing the part of the texture I wanted…
It is possible that I am not using these components the intended way, so feel free to make suggestions.
Thanks.
I’m trying to achieve the same sprite splicing effect and I think i resolved your problem.
You used “new Vector2(50,50)” for the pivot but the pivot is in 0,1 range. Just replace it with new “Vector2(0.5f,0.5f)”. Your sprite should even be displayed atm but its far away from where you expect it to be. Although this fixed it for me I had problems with the scaling. It works using 40 for the texels per unit which is really strange. So here is my code: