Hi, I’m trying to make a little pixel transition a-la pokemon battle transition.
To do that I need to write pixels per frame to a Texture2D and then set the gameobject’s spriterenderer’s sprite.
My script creates a Texture2D as I want it, I can tell in the editor. But creating a Sprite from that doesn’t seem to work.
void Awake () {
frame = new Texture2D(size, size);
for (int x = 0; x < size; x++){
for (int y = 0; y < size; y++){
frame.SetPixel(x, y, color);
}
}
frame.Apply();
sprit=new Sprite();
sprit=Sprite.Create(frame, new Rect(0f,0f,size,size), new Vector2(0f,0f));
gameObject.GetComponent<SpriteRenderer>().sprite=sprit;
}