I've got a diver with a depth finder which ranges from green to red (see picture). I'd like to crop that texture on the fly so I can determine the shown amount of the bar myself. How can I proceed to make this work? This code from the unity-documentation using SetPixels() didn't work at all. Code (csharp): exture2D sourceTex = renderer.material.mainTexture as Texture2D; int x = 50; int y = 30; int width = 100; int height = 100; Color[] pix = sourceTex.GetPixels(x, y, width, height); Texture2D destTex = new Texture2D(width, height); destTex.SetPixels(pix); destTex.Apply(); renderer.material.mainTexture = destTex;
You probably want to tweak the tiling and offset values of the material, which determine what part of the texture are shown.