How to set pivot of gameObject on import


#1

very stupid question, but I can’t find any solution.How to set pivot of go in the centre, not top left ?


#2

maybe someone need, this code helped
if (thisGoHC.GetComponent() != null)
{
Collider2D col = thisGoHC.GetComponent();
thisGoHC.GetComponent().offset = Vector2.zero;
thisGoHC.transform.position += Vector3.up * (-0.5f) * col.bounds.size.y + Vector3.right * col.bounds.size.x * 0.5f;
}

still,is there an easier way to do this right in tiled(for example i don’t know sign of collider offset ±yx)?


(Seanba) #3

Hi BoriYashin, you could write a custom importer for this kind of thing. You can read up a bit about custom importers here: http://www.seanba.com/megadadadventures.html

(See the example of ‘appearing blocks’.)


#4

Thnk You a lot, used this in “handleCustomProps”

thisGoCA.transform.position += Vector3.right * (-1) * thisGoCA.GetComponent<Collider2D>().bounds.size.y / 2 +
            Vector3.up * thisGoCA.GetComponent<Collider2D>().bounds.size.x / 2;
            thisGoCA.GetComponent<Collider2D>().offset.Set(0,0);