2
votes

I imported an SVG image (acd.svg) in my project that sits in "Resources/svgs". Selecting the SVG, the Importer settings opens in the Inspector where I have selected the option "Vector Sprite" as "Generated Asset Sprite". I can succesfully drop the SVG sprite in the scene (in my case in a Canvas and it is correctly visible) and the Sprite Renderer component gets the Sprite field set to acdSprite.

Now, I would like to change programmatically the Sprite in this "SymbolObject" component but I fail to understand where the acdSprite is located.

I tried something like:

symbolObject.GetComponent().sprite = (Sprite) Resources.Load ("svgs/acd");

but I get an InvalidCastException . My question is: How can I access the acdSprite in Unity code programmatically?

I'm using Unity 2019.1.0f2 and the SVG support seems to work quite fine

svv

2

2 Answers

0
votes

Pass the Reference of Imported SVG File through Public Gameobject in unity.

 public GameObject svgImage;
 private void LoadsvgImage()
    {
    Sprite sprite = svgImage.GetComponent<SpriteRenderer>().sprite;

    }
0
votes

Give it a go lad.

function Start() {
    GetComponent(SpriteRenderer).sprite = image;
}