Hello Guest

Author Topic: change sprite by code  (Read 4539 times)

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
change sprite by code
« 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: change sprite by code
« Reply #1 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.

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: change sprite by code
« Reply #2 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: change sprite by code
« Reply #3 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.

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: change sprite by code
« Reply #4 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: change sprite by code
« Reply #5 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.