Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: kjenkins_oculus on November 05, 2013, 01:42:50 PM
-
I have a checkbox with two different textures - checked, and unchecked. Only one should show at a time. But UIToggle's Sprite field only turns on or off one sprite, rather than alternate between them.
I can do this with code, but I am thinking nGui already has a way to do this. Maybe with Group?
Thanks for any suggestions.
-
I ran into a similiar issue. The following is code straight from my button handling routine. Make sure you have both Sprites on the same Atlas and it becomes pretty easy. I have the following hierarchy on the Game Objects for the button:
Hierarchy
- buttonSettingsKnowledge (This is the UIPanel or UIDragPanelContents as in my case & the Box Collider)
- Name (This is the text on the button)
- StateActive (This is the UISprite for the X or check.)
- uiSpriteButton (This is the UISprite for the button image)
Code
// Toggle the controlled function: Knowledge
if( selectionIn == "buttonSettingsKnowledge" ) {
// Toggle the feature (button setting & view)
if( !bSettingsKnowledge ) {
bSettingsKnowledge = true;
settingsKnowledgeActive.transform.GetComponent<UISprite>().spriteName = "signGreenCheck_50";
}
else {
bSettingsKnowledge = false;
settingsKnowledgeActive.transform.GetComponent<UISprite>().spriteName = "signRedX_50";
}
}
Hope it helps!