2D Toolkit Forum
2D Toolkit => Support => Topic started by: Lorax on January 30, 2014, 12:56:14 am
-
I have a sprite (body) that is attached to an empty game object. I have several other sprites attached to the body at attachment points and together these pieces look like a rodent. The rodent scurries around and I'd like to have a piece of the rodent (attached sprite) when the rodent is hit as the rest of the rodent continues to move and its attachment is left behind.
I have been trying to figure out how to:
-Get the position and rotation of the attached sprite when hit
I tried using thisSprite.GetBounds(). I get the 'center' and 'extents' returned. Are these points relative to the game object that the mother sprite is attached to?
-Remove an attached sprite
I know how to change the sprite with thisattachedsprite.SetSprite(sprite ID), but I'd like to entirely remove the sprite (so that the rat has no tail)
-Create empty game object at position of attached sprite when hit
var go = new GameObject(); and then set its transform.position to the position of the sprite being 'ripped off'
-Attach 'removed sprite' to new game object
Thank you to any advice you can offer. I'm continuing to research, experiment and get new errors!
-Laura
-
GetBounds is local to the sprite transform. You can also use renderer.bounds which is in world space.
To remove the tail and leave it behind, couldn't you just detach the sprite? sprite.transform.parent = null?