Author Topic: UIToggle with two different textures  (Read 2810 times)

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UIToggle with two different textures
« 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.

mvesich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: UIToggle with two different textures
« Reply #1 on: November 05, 2013, 03:28:49 PM »
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!