Search Unity

Assign/access a button's "Pressed Sprite" at runtime

Discussion in 'UGUI & TextMesh Pro' started by Andrei_Leonte, Nov 4, 2014.

  1. Andrei_Leonte

    Andrei_Leonte

    Joined:
    Mar 13, 2014
    Posts:
    14
    I was curious if you could do this in code. I have prefabs from which I instantiate button objects at runtime, these prefabs' Button component has a Sprite Swap transition. I'm able to change the main image of the instances, but can't find a way to change the pressed image.

    The purpose is to have a small number of prefabs with different properties which I can then select and combine in the instances, for example the Text children of prefab A combined with the sprites of prefab B.
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    You want to look at the btn.spriteState.pressedSprit. The spriteState also contains the highlighSprite and disabledSprite.
     
  3. Andrei_Leonte

    Andrei_Leonte

    Joined:
    Mar 13, 2014
    Posts:
    14
    Thank you, it worked.
     
  4. JKimDev

    JKimDev

    Joined:
    Dec 20, 2017
    Posts:
    1
    how do you use this pls explain im new thanks!