Question by
CptBubbles · Dec 01, 2015 at 12:24 AM ·
2dscripting problemspritetexture2dprocedural-generation
[SOLVED] Problems creating a Sprite through script
Hi,
I have to generate a texture at runtime, which I do in a script with simplex noise. This works totally fine, so I end up with a Texture2D that looks ok (I tested this by saving the Texture2D as a png).
But when I try to apply this texture to my game object's SpriteRenderer component, the texture that is displayed is just solid grey. This is how I apply the texture (the texture is 200x200 pixels large)
island.GetComponent<SpriteRenderer>().sprite = Sprite.Create(tex, new Rect(0, 0, 200, 200), new Vector2(0.5F, 0.5F));
edit: I got it to work. After creating the Texture2D for the sprite, I had to call tex.Apply()
Comment