Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Copying UI elements

Discussion in 'UGUI & TextMesh Pro' started by Oxylis, Jul 19, 2015.

  1. Oxylis

    Oxylis

    Joined:
    Jul 19, 2015
    Posts:
    4
    Hi all,

    Thank you in avdance for spending a couple of minutes looking at this thread.
    I'm not sure I'm using the right methodology here so a direction would be great appreciated.


    What I'm trying to do: 2 canvas in my scene. On the left nothing. On the right 3 tiles. I'd like to drag a sticker from the right to the left. But when I drag it I don't want to take the current one, I'd like to create a copy of it, so I can have as many as I'd like on the left hand side.


    I've looked at inventories tutorial and while they do most of the work I can only drag the item from on place to another, not instanciating it.

    While i'll love to get the code writen for me :p I would really appreciate what would your approach be instead?

    Thabk you
     
  2. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    From what I understand, you can just use Instantiate to create a clone of the right sticker and then drag that clone to the left. Instantiate, after all, works with all GameObjects, not just prefabs.
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    when you click on the item have the onClick instantiate a clone of that object & then drag it. You will need to check that there aren't multiple items stacked in the one panel though or you might have issues with the number of items in game etc.(where the player clicks & doesn't drag but then thinks it didn't work so clicks & drags again.)
     
  4. Oxylis

    Oxylis

    Joined:
    Jul 19, 2015
    Posts:
    4
    Thank you that makes sense and that helps me to look at the direction. So my initial tile could be anything really in this case, like a button, or an image. I would use prefabs though as I think I'd reuse them more as I go. Thanks!

    Thanks for that, yes good point, I'll make sure these instances are destroy if "un-used" I guess. Again thanks for your direction.

    One step at a time :)