Add a child GameObject to a tk2d sprite dynamically

Hello everyone,

I have a 2D character with “Idle” animation, (3-4 frames) and I am using tk2d.
When I hit my character, I need to add a scarf/injury (png) to the hit point.

I am able to Instantiate at hit point.
I am able to make it child to the enemey character.
But the problem is that the sprite moves, and its not the transform.position that changes, but the textures…
and as a result, the scarf stays at its place, where the character moves.

I can’t figure out a method to stick my png to the hit point…
Maybe there’s a way to change the texture atlas dynamically?

Sure I can have tons of millions of textures… with a scarf at each position … bla bla…
sure not thinking of that dumb way…
As I have many characters/levels…

Hope to get some hints…
thanks

Sounds like you have the correct solution, but you may be doing something wrong.

I suggest this:

  1. Create a scarf prefab (by using Create → tk2d → Sprite in the hierarchy and saving it as a prefab)
  2. Set your character script to have a public GameObject scarfPrototype object.
  3. Instantiate that prefab as needed: GameObject scarf = Instantiate( scarfPrototype, ...)
  4. Parent it: scarf.transform.parent = transform

There is no reason this should not work. If it doesn’t please provide more info or code.