Link Sprite Resolver to a UI Image?
Asked Answered
G

0

2

I am currently using the Sprite Library and Sprite Resolver components on my in-game player object, which has a Sprite Renderer. This is very useful for swapping out the animation sprites all at once based on the selected character.

I tried doing the same thing on a UI Image object (which has the Image component rather than a Sprite Renderer), but the Image component’s Source Image does not change when selecting the sprite in the Sprite Resolver (i.e. the two components don’t appear to be linked in any way).

Is there a way to link these components, or to accomplish what I’m trying to do in another way?

Geometric answered 17/7, 2023 at 18:51 Comment(3)

I was able to do this, although I doubt this was the intended way. My GameObject img has both the Image component and Sprite Renderer components attached. I disable the Sprite renderer through the UI and set the Image sprite to the Sprite Render sprite like this: img.GetComponent<SpriteResolver>().SetCategoryAndLabel(cat, lab); img.GetComponent<Image>().sprite = img.GetComponent<SpriteRenderer>().sprite;

Roseannaroseanne

Thanks for the answer, I will try and see if I can get that to work

Geometric

Got it working after a good bit of struggling with the animation controller. Thank you!

Geometric

© 2022 - 2024 — McMap. All rights reserved.