0
votes

Im creating a sprite like this:

Sprite.Create(myTexture,new Rect(0,0,myTexture.width,myTexture.height),new Vector2(1,1),100);

But the sprite is not appearing anywhere. What I'm doing wrong?

1

1 Answers

1
votes

Because you also need SpriteRenderer to render your sprite.

void Start () {
    Sprite mySprite = Sprite.Create(myTex, new Rect(0, 0, myTex.width, myTex.height), new Vector2(1, 1), 100);

    GameObject myObj = new GameObject();
    SpriteRenderer spriteRenderer = myObj.AddComponent<SpriteRenderer>();
    spriteRenderer.sprite = mySprite;
}