Hi All,
I am trying to change the texture of a sprite with SetPixel. It works, but the problem is that the changes are persistent. If I stop the game, the texture stays changed.
This is my code:
void Start()
{
//create a copy of the original sprite and set it to the sprite
Sprite temp_sprite = Instantiate(gameObject.GetComponent<SpriteRenderer> ().sprite) as Sprite;
gameObject.GetComponent<SpriteRenderer> ().sprite = temp_sprite;
//draw the pixels
int y = 0;
while (y < temp_sprite.texture.height)
{
int x = 0;
while (x < 10) {
Color color = Color.blue;
temp_sprite.texture.SetPixel(x, y, color);
++x;
}
y++;
}
//apply the texture to the sprite
temp_sprite.texture.Apply();
}
I have no idea why it does not work. Am I making a mistake in the copy somewhere?