2D Toolkit Forum

2D Toolkit => Support => Topic started by: atmuc on April 17, 2014, 06:08:26 pm

Title: change sprite by code
Post by: atmuc on April 17, 2014, 06:08:26 pm
i can change sprite using "void tk2dBaseSprite.SetSprite (int   newSpriteId)". how can i change collider by code? when i chande sprite from unity inspector it also change collider that i set on sprite collection editor. i want to the exactly same operation that inspector dropdown change does.
Title: Re: change sprite by code
Post by: unikronsoftware on April 18, 2014, 05:08:23 am
If its a poly collider, it can't animate when using 3d physics - it only works with 2D physics. This is due to performance reasons.
Title: Re: change sprite by code
Post by: atmuc on April 18, 2014, 06:58:42 am
i think i could not explain my problem. i set different polygon collider for each sprite on Sprite Collection Editor. on my game object inspector when i select collection and sprite, it changes polygon to what i edit on Sprite Collection Editor. i want to do that by code. like this;

change sprite
remove current collider
add collider define on Sprite Collection Editor

can i do that?
Title: Re: change sprite by code
Post by: unikronsoftware on April 18, 2014, 07:03:46 am
Yea I understood the question - you can't animate 3d polygon colliders (i.e. can't change them). It is only created in the editor. You can modify the code to enable this, or if you use 2D physics instead of 3D, it will just work as expected.
Title: Re: change sprite by code
Post by: atmuc on April 18, 2014, 07:07:40 am
it is 2d polygon collider, but "void tk2dBaseSprite.SetSprite (int   newSpriteId)" does just change sprite graphics not collider. after i change sprite by code i still see the first collider.
Title: Re: change sprite by code
Post by: unikronsoftware on April 18, 2014, 07:13:33 am
You're using 2D physics? Please post a repro case so I can investigate this. It should work fine with 2D physics, just not 3D.