Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpriteMaker : MonoBehaviour {
- public GameObject[] mSprites = new GameObject[10];
- public Texture2D mTexture;
- public Texture2D mTexture2;
- // Use this for initialization
- void Start () {
- mSprites[0] = AddSprite(mTexture, "name", 50,50);
- mSprites[0].transform.position += new Vector3(0,30,30);
- }
- public GameObject AddSprite (Texture2D tex, string name, int width, int height) {
- Texture2D _texture = tex;
- Sprite newSprite = Sprite.Create(_texture, new Rect(0f, 0f, width, height), new Vector2(0.5f, 0.5f),128f);
- GameObject sprGameObj = new GameObject();
- sprGameObj.name = name;
- sprGameObj.AddComponent<SpriteRenderer>();
- SpriteRenderer sprRenderer = sprGameObj.GetComponent<SpriteRenderer>();
- sprRenderer.sprite = newSprite;
- return sprGameObj;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement