Search Unity

How can convert a UI item to normal item in runtime

Discussion in 'General Discussion' started by mfatihbarut, Jan 20, 2021.

  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,060
    Hi all,
    I want the player to see a star in the middle of the screen (as a UI element).
    Then when he presses it I want the star to go down and stick to the character's head and shows the character is upgraded. How can I do it?
     
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Look in the API at those classes and decide which of the dozens of methods is best suited to your game mechanic.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    For starters, you don't convert from one to the other. Instead you keep three different objects. One to represent the item in the UI and one to represent the item in the world. When the player "selects" the item in the UI you enable or instantiate the one in the world, animate it, and then attach it to the player once the animation ends.
     
  4. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,060
    Thanks the only thing is;
    How to align the first UI item and the second (transition) item? One of them is UI and its position calculated by rect transform and the other's position is calculated by world transform.
    It is not easy to create an illusion without breaking some frames.. (you know what I meant)
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
  6. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,060
    any solution for scaling?
     
  7. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    transform.localScale = new Vector3.one * wantedScale;