how to check if a sprite in an array is the current sprite

Hello!

I’m making a 2d fighter, and my hitboxes are activated/deactivated by the currentSprite.sprite.

currentSprite = GetComponent();

for example:

if (jabSpriteHitFrame == currentSprite.sprite)
{
JabBox.gameObject.SetActive(true);
}
else
JabBox.gameObject.SetActive(false);

this works perfectly for single-frame attacks, but I have a few multi-frame attacks and would like a similar code to access the currentSprite from an array rather than declare a bunch of frames and repeat the above code.

something along these lines:

public Sprite[ ] flashkickActiveFrames;

if (flashkickActiveFrames == currentSprite.sprite)
flashkickBox.gameObject.SetActive(true);

else
flashkickBox.gameObject.SetActive(false);

thank you!

You would have to use a for loop to iterate through the array of sprites. That isn’t a good solution for your problem though. Iterating through a list of sprites every frame isn’t very efficient.

I would use an animation event to turn on the flashkickBox. You can control exactly which frame it will be triggered, and seeing as you are already using the animator why not.

1 Like

great idea! thanks for the insight.