Sprite Code for Unity and Desktop Photo

Posted by (twitter: @Local_Minimum)
December 13th, 2013 7:47 am

Unity 2D Sprite Animation

I spent the warmup weekend cursing the collision detection in the new 2D mode in Unity for several hours until I realized that there was a new OnCollisionEnter2D. Makes sense, but lesson learned: know your tool before starting. I would have been so frustrated if those hours had been tomorrow afternoon, that I don’t know what would have happened.

After that debacle, I made a Unity2D Sprite Animation Script that I think turned out pretty nice and easy to use. Probably there are better and more efficient out there, but since we’ll probably use it, it needs to be available. So here you go. If you want to use it, consider it public domain.

Short instructions: Use Unity’s sprite editor to break up sprite sheet(s) into sprites. Then add one SpriteAnimator per type of animation you want on your game object (e.g. ‘walk left’, ‘walk right’).
Add one SpriteAnimationSelector to the game object with the SpriteAnimator(s). The CharacterController is not a full controller by any means, but it shows how to interface with the SpriteAnimationSelector.

Finally, this is where we’ll code, more computers are coming:

The living room game making table of the turmeric jam jar.

The living room game making table of the turmeric jam jar.

And here’s where we’ll try our luck with using stop-motion in making the game:

The animation corner of the turmeric jam jar.

The animation corner of the turmeric jam jar.


All from our living room.

Tags: , , , ,


5 Responses to “Sprite Code for Unity and Desktop Photo”

  1. TobiasW says:

    Is the sprite animation Unity has inbuilt only limited to pro, or is it just not to your taste?

  2. PockeTiger says:

    I suppose it’s not his taste. The animator is fully available in the free version along with most of the 2D Toolset as far as I know.

    PixelNest just made a nice little tutorial on the topic. Link below:
    http://pixelnest.io/tutorials/2d-game-unity/animations-1/

  3. Just a show of how little I’ve actually used Unity so thanks for the link! I’ll check it out tonight, but depending on complexity, simply switching different groups of animations without having to learn a lot of new things during the few hours of the compo/jam may become too tempting…. the post was mostly for following rules and the code for refreshing Unity coding skills.

  4. Checking the instructions it seems like a sweet system built around having parts to animate into complex wholes, but a little overloaded for when animations are intended to be a sequence(s) of prefabricated sprites. Still, I should stop writing replies and start testing and learning. Won’t be time tomorrow to get stuck on new things!

  5. TobiasW says:

    You should definitely check out
    – This tutorial project: https://www.assetstore.unity3d.com/#/content/11228
    – The walkthrough video about it: https://www.youtube.com/watch?v=4qE8cuHI93c

    They use key-based animation like in the link above (for things like the player character) and sheet-based animation like you (for things like the swan in the background).

    The best thing is that it’s totally transparent which animation type is used from the code side – and really, there isn’t any difference: Key-based animation animates the position/rotation properties, and sheet-based animation is key-based animation that animates the sprite-property of the Sprite Renderer.

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]