Im working in Unity and im finding the animator isnt working for what im trying to do in my 2d game. What I want to do is build a specific animation using sprite sheets, then be able to reuses that same animation with other sprites that are the same size and dimensions by cells. After researching for a while im seeing thats not possible. So what im trying to do is create my own animation script, but what I dont understand is how to tell unity to draw only a section of the sprite. Say like in xna when you could render only a rect of a sprite with the start and end coordinates of the rectangle.
I think there can be a simpler approach in which you can do this , and still use Unity Mecanim for the animation. Steps:- 1) You can programatically assign texture 2D sprites from the image, and as it is a grid it wont be much difficult to do so. In the following answer the user has created his own sprite slicer and saved into the directory (optional else just save it in a variable). You don't need the whole code,just check the GetSprites() function and you will get the idea :) http://answers.unity3d.com/questions/576799/coding-my-own-auto-slicer-getting-islands-of-pixel.html 2) Once you are able to do that, then maintain an Array of sprites, which you got from step 1. 3) Now you need to create an anim file of these sprites which can be plugged into mecanim. For this you need Unity's Set Curve function(check the link provided below). Once you have the clip its upto you whether to save it for future use or just have it in a variable for the current game instance only. http://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html Hope this resolves your doubt :) |
||||
|