1
votes

I have 64x64 texture of tree :

enter image description here

but output gives me this (black messed object is my tree)

enter image description here

If i drag sprite into editor, its rendered as meant to be(with new gameobject created). But im accesing it through script :

public Sprite treesIcon;

SpriteRenderer sr;

TileTypeHandler typeHandler;

void Start () {
    sr = GetComponent<SpriteRenderer>();
}


void Update () {
    switch(typeHandler.tileType) /// nevermind enum, its edited
    {
        case TileType.Woods:
            {
                sr.sprite = treesIcon;
                break;
            }
    }
}

point is to dynamically change textures.

Can anyone explain me this behaviour? Is there somethin I am missing about sprites and textures? How can i fix it?

1
Can you post a screenshot of the editor (when running) of the GameObject you have the sprite set. I think this is a problem with the shader, or the alpha channel. - AntiHeadshot
Actually you were right. It was problem with shader! Thanks much! - Bob T.

1 Answers

1
votes

The result looks like the SpriteRenderer is using the wrong shader, change the Material to Sprites-Default, and it should work.

Would you have colored images, you immediately would see that there is something wrong, because they would also appear black.