- Home /
Question by
diamondgaming250 · Aug 08, 2021 at 07:33 PM ·
animationspriteanimatoranimator controllerspriterenderer
Change sprite in a sprite renderer with an animation
I'm making a Plants vs Zombies fan game and i have a plant that when its health gets lower his sprite changes, but also has an animator that only changes scale and position, i have the plant's sprite renderer and the sprites for the plant getting worse, i made this script:
if (affectedBodyParts.Count > 0)
{
for (int i = 0; i < affectedBodyParts.Count; i++)
{
if ((currentHealth <= (health / 2f)) && (currentHealth > (health / 4f)))
{
affectedBodyParts[i].sprite = medHealthyBodyParts[i];
}
else if (currentHealth <= (health / 4f))
{
affectedBodyParts[i].sprite = unhealthyBodyParts[i];
}
else
break;
}
}
The sprite changes, however it only does it for like 1 frame, i searched solutions for this i tried everything, setting Write Defaults to false, putting the script on LateUpdate, and nothing works. Any help would be very grateful
Comment
Your answer
Follow this Question
Related Questions
Animated GUI sprite not animating. 0 Answers
Multiple Animation Controllers 1 Answer
Can't animate Sprite correctly 0 Answers
2D sprite animation issue 0 Answers
Compile error with animator 1 Answer