- Home /
Question by
Olgo · May 11, 2015 at 06:57 PM ·
texture2ddynamicallygetpixelsetpixel
Dynamically created texture is off in BFE...
Hey guys, I've got a script that takes a sprite, creates a new texture to dynamically create "shadows" of the original texture by changing any non-0 alpha pixels to a "shadow" color. However, for some reason, it is set far away from its origin in Scene view.
public static Sprite GetShadow( Sprite sprite ){
Texture2D newTexture = new Texture2D(sprite.texture.width, sprite.texture.height, sprite.texture.format, false);
for( int x = 0; x < newTexture.width; x++ ){
for( int y = 0; y < newTexture.height; y++ ){
if( sprite.texture.GetPixel(x,y).a != 0 ){
newTexture.SetPixel(x,y, shadowColor);
}else{
newTexture.SetPixel(x,y, Color.clear);
}
}
}
newTexture.Apply();
sprite = Sprite.Create( newTexture, sprite.rect, sprite.pivot, sprite.pixelsPerUnit );
return sprite;
}
what gives?
broken-texture.png
(41.4 kB)
Comment