Search Unity

Resizing an image

Discussion in 'UGUI & TextMesh Pro' started by Undiscovered, Sep 20, 2017.

  1. Undiscovered

    Undiscovered

    Joined:
    Apr 5, 2014
    Posts:
    53
    I am displaying an image within my panel which when clicked I would like it to increase in size. When the image is clicked again I would like it to revert back to its original size?

    Can anyone offer any assistance?

    Thanks
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    Depending on whether you want to lerp the size change. You need to create a script and attach it to the "clickable Object" using the IPointerClick interfaces, then in the implemented methods, you have two options.
    Either:
    • Create an animator on the Image to scale it. Then have a reference to the animator and activate it on click
    • On click, just manually set the scale values.
    The SelectableExtension and the NonDrawingClickable controls in the Unity UI Extensions (link in signature) project provide the click behaviours so you can use or copy them to suit your needs.
    Hope that helps.