Skip to content

Instantly share code, notes, and snippets.

@yanniboi
Created May 28, 2021 20:10
Show Gist options
  • Save yanniboi/8c29f51a3defad38952328f0c5b99440 to your computer and use it in GitHub Desktop.
Save yanniboi/8c29f51a3defad38952328f0c5b99440 to your computer and use it in GitHub Desktop.
Spike Collider for longy.
public class SpriteChange : Monobehaviour
{
public Sprite[] spriteArray;
public Sprite spikeSprite;
public SpriteRenderer spriteRenderer;
public int currentSprite;
private void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag == "spike")
{
spriteRenderer.sprite = spikeSprite;
}
else
{
spriteRenderer.sprite = spriteArray[currentSprite];
currentSprite++;
if (currentSprite >= spriteArray.Length)
{
currentSprite = 0;
}
}
}
}
@Longy335
Copy link

so now for some reason the spike destroys the heart all together and still when i collide with the floor the sprite changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment