Skip to content

Commit

Permalink
Add error checking before setting sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgraham committed Jan 6, 2022
1 parent 56558cf commit 8e5b218
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;

public class Player : MonoBehaviour
{
Expand Down Expand Up @@ -47,7 +47,9 @@ private void AnimateSprite()
spriteIndex = 0;
}

spriteRenderer.sprite = sprites[spriteIndex];
if (spriteIndex < sprites.Length && spriteIndex >= 0) {
spriteRenderer.sprite = sprites[spriteIndex];
}
}

private void OnTriggerEnter2D(Collider2D other)
Expand Down

0 comments on commit 8e5b218

Please sign in to comment.