I have only one small simple question, for which I didn’t find answer while searching Google. How do I get the name of the sprite which I have added to a Source Image of UI Image component? and also get the name of the sprite added to the 2d sprite game object in a 2d game.? Please someone help me…
That should be simple, unless I’m missing something:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SomeScript : MonoBehaviour
{
public Image image;
void Awake()
{
string name = image.sprite.name;
// DO SOMETHING
}
}
Putting this here in case someone is wondering. Here’s the actual way.
GetComponent<SpriteRender>().sprite.name;
I dont think that is possible. I had similar problem when I wanted to compare 2 sprites. The closest you can define a sprite is by texture.name and textureRect.