Search Unity

Creat sprites map by script.

Discussion in '2D' started by Yura-Agafonov, Apr 28, 2016.

  1. Yura-Agafonov

    Yura-Agafonov

    Joined:
    Nov 24, 2014
    Posts:
    22
    I have .psd file as Sprite2D/Multiple. I want to creat sprites map by script.

    Code (CSharp):
    1. Texture2D testTexture =  Resources.Load<Texture2D>("TILES_000");
    2.             Sprite MySprite = Sprite.Create(testTexture, new Rect(0, 20, 40, 40), new Vector2(0, 0), 500);
    3.             GameObject _gameObject2 = new GameObject("test2");
    4.             _gameObject2.AddComponent<SpriteRenderer>();
    5.             _gameObject2.GetComponent<Transform>().position = new Vector2(1, 1);
    6.             _gameObject2.GetComponent<SpriteRenderer>().sprite = MySprite;
    ... and field sprite is empty