How can I set sprite for UI2DSprite from NGUI at runtime?

This is what I tried:

gameObject.GetComponent<UI2DSprite>().sprite2D = Resources.Load<Sprite>("Assets/Content/UI/level/notLife.png");

I tried not to write .png in the end but it did not help as well.

Here is my Project view so that to prove you that I am using the right path:

enter image description here

And the problem here is that instead of showing me the newly placed sprite my old one disappears and nothing else happens.

So, how can I change sprite in UI2DSprite in NGUI from script?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.