I’m trying to set the sprite of a prefab in script
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
spriteRenderer.sprite = sprite;
The result is either sprite ends up as Type mismatch but actually works or the sprite ends up as None
What am I doing wrong? How am I supposed to create a sprite from a texture in script and apply it to a spriteRenderer?