Search code examples
unity-game-engineanimation

A couple of questions about resizing and animating sprites


I'm programming a very simple proof of concept game in which bandits attack a knight. Nothing fancy.

I did Google and YT before I wrote this. :)

My questions :

a) How do I resize the sprite to scale? I found a way to do so by using Draw Mode - Sliced, but I lucked into a window where I could rescale the X and Y axis, but then I closed it.

b) How do I make it so that the bandit only does damage during a certain part of the animation? (the sword swing) I have the sprites and animation, but no idea how to isolate it.

Google and ChatGPT tell me to use a Sprite Mask but that's not really what I want.

The process of making the game is fun but also challenging...is that part of the software design process in which you have to constantly be fixing things and finding better ways to iterate?

a) I tried to find a way back to the window and failed.

b) I thiinnnnkkk this might be a solution

https://forum.unity.com/threads/is-there-a-way-to-get-a-a-part-of-an-animated-object-to-appear-and-play-at-a-specific-keyframe.928347/

but I am not sure how to get it to work. Also my animator doesn't display the actual animation for some reason.


Solution

  • a) How do I resize the sprite to scale?

    There's a couple different ways.

    1. You can change the "Pixels Per Unit" attribute of the sprite asset (X pixels = 1 Unity unit). Default is 100, so setting it to 50 would double the size.
    2. You can change the transform scale of the object containing the SpriteRenderer/Image.

    Tiled / Sliced rendering modes are for 9-sliced or repeating the same sprite over an area, not for resizing single sprites.


    b) How do I make it so that the bandit only does damage during a certain part of the animation?

    In an animation clip, you can add Animation Events, which can call functions in the attached scripts at a certain point of the animation. What I'd do is add "EnableHitbox" and "DisableHitbox" events to your attack animation, and use those to know whether or not to do your enemy-attacking logic. (Physics2D Raycasts or Overlap[Shape] calls, whatever works.)