Good day,
I’m trying to make a game and I just write a code to change sprites (weapons) with “space”:
public Sprite sprite1; // Drag your first sprite here
public Sprite sprite2; // Drag your second sprite here
private SpriteRenderer spriteRenderer;
void Start () {
spriteRenderer = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) // If the space bar is pushed down
{
ChangeSprite(); // call method to change sprite
}
}
void ChangeSprite ()
{
if (spriteRenderer.sprite == sprite1) { // if the spriteRenderer sprite = sprite1 then change to sprite2
spriteRenderer.sprite = sprite2;
} else {
spriteRenderer.sprite = sprite1; // otherwise change it back to sprite1
}
}
}
And now I would like to make animations for each of sprite (attacking animations), but I have no idea how. Is there any simple way to make attack animations with possibility to change weapon? Maybe there is tutorial, but I can’t find it?
Thank you, sorry for English mistakes.