Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: godik on July 26, 2013, 12:32:46 PM

Title: [Problem] Cloning object takes units instead in pixels. Greater Object.
Post by: godik on July 26, 2013, 12:32:46 PM
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. }
Title: Re: [Problem] Cloning object takes units instead in pixels. Greater Object.
Post by: ArenMook on July 27, 2013, 01:23:15 PM
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.