Search code examples
imageunity-game-enginespritetexture2d

is it possible in Unity to slice image from the middle?


I get an image from the backend which I want to put in a puzzle shuffle game, however right now it is cropping from left to almost middle of the image , I would like to crop the center of the image, I was trying to use another Sprite which I cropped to the middle then use it in the ImageSlicer however I am getting same results. Here are the images :

Main Image , Cropped Image as temp , Sliced Image as imagesSlices

am I doing the right thing and maybe I'm messing something in the code or this isn't how I should crop and slice ?

Sprite temp = Sprite.Create(currentImage, new Rect(currentImage.width * 0.25f, 0, currentImage.width * 0.75f, currentImage.height),new Vector2(0.5f, 0.5f), 100.0f);

Texture2D[,] imageSlices = ImageSlicer.GetSlices(temp.texture, blocksPerLine);

Solution

  • So the texture was staying the same and I was trying to get a new sprite not a new texture but I need a new cropped texture to work with which is why the sliced images were taken from old texture.