Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Codewalker on June 28, 2012, 11:51:30 AM
-
I have a UISprite and want to assign an atlas by using the name (i.e. a string). Does NGUI has a useful function for this? (I could not find one in the documentation)
-
Not sure the question you're asking is meaningful. Are you saying that you have programatically created a UISprite at runtime and are trying to shove it into an atlas at runtime? That's not how atlases work...
-
No, I have a UISprite (regurlarly designed and placed in the Unity Editor) that should get a (not randomly chosen but) different texture. However, these textures may be part of several atlasses. So I have not only to change the sprite name (a string that I set via script), but also the atlas. And it seems, I can't set an atlas just by it's name. Hope, this makes it clearer.
-
That's because the atlas is a reference. You need to choose it from some list you keep locally, or place it in the Resources folder and Resources.Load it.
-
but how can i assign the atlas to the sprite? i have the same problem with a UILabel and i do not see a way to do something like uilable.atlas = myatlas.
i have everything ready to load from ressources but i do not see the command to assign it in code.
here is what i do:
Label = new GameObject();
Label.AddComponent<UILabel>();
Label.GetComponent<UILabel>().text = text;
when i start the project i see a gameobejct with an uilabel attached but it has no atlas => it does not show the text
-
UILabel.font.atlas -- for labels the atlas is on the font, not on the label. Sprites have the atlas on UISprite.atlas. Since you're using a label, you need to specify its font before you use it.
-
aaaah! i was not deep enough. sigh, that is embarrassing.
thanks for clearing it up