Author Topic: [Problem] Cloning object takes units instead in pixels. Greater Object.  (Read 1895 times)

godik

  • Guest
I have done  2 UIgrids, one with the items and another one empty. When i doubleclick on one item of the source grid i want it to clone in the destination grid.

The problem i found is that the transform of the clone object is in units and not in pixels. The effect is that the object is a lot greater than the original.
I clone with:
  1.         GameObject clone = (GameObject) Instantiate(collider.gameObject);
  2.         destino.addElement(clone);
  3.  

The method addElement from destination UIgrid:
  1. public void addElement(GameObject element)
  2. {
  3.         element.transform.parent = transform;
  4.         Reposition();
  5. }
« Last Edit: July 26, 2013, 05:02:07 PM by godik »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
1. Never use Instantiate. NGUITools.AddChild should be used instead. Instantiate doesn't set the parent, object layer, and doesn't clear the transform correctly.
2. Don't set the parent. NGUITools.AddChild does it for you.