Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created March 13, 2015 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unitycoder/2be9dea1acde0c210f94 to your computer and use it in GitHub Desktop.
Save unitycoder/2be9dea1acde0c210f94 to your computer and use it in GitHub Desktop.
Assign texture2D to sprite
// need to create new sprite, cannot assign or convert Texture2D into sprite
Sprite sprite = Sprite.Create (tex, new Rect(0,0,tex.width,tex.height), new Vector2 (0, 0), pixelToUnits);
GetComponent<SpriteRenderer>().sprite = sprite;
http://docs.unity3d.com/ScriptReference/Sprite.Create.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment