- Home /
Repeat Bonus Sprite - UnityScript
INTRO:
I'm using UnityScript and I'm still learning as I go. I am working on a match-3 game and it runs great. My issue is calling up sprites for bonuses. Right now I'm calling each sprite individually when a certain condition is met; however, this is very repetitive since I have to write code for each bonus individually.
CODE EXPLANATION:
I have a few lines of code that checks if the bonus condition is met (with some other conditions to double check that a bonus does not count twice).
It checks if the sprite has been used
If not, it will use the appropriate sprite in numerical succession
Each sprite/variable is named in succession, such as chain02Sprite, chain03sprite...and so on.
CODE:
function ScoreChain()
{
if(bonusCheck == false && chainTrigger == true && gameManagerScript.chainMultiplier == 2 && gameManagerScript.chain02Sprite == false)
{
bonusCheck = true;
gameManagerScript.chain02Sprite = true;
sprite.SetSprite("sprites_+2");
BonusAnimation();
}
if(bonusCheck == false && chainTrigger == true && gameManagerScript.chainMultiplier == 3 && gameManagerScript.chain03Sprite == false)
{
bonusCheck = true;
gameManagerScript.chain03Sprite = true;
sprite.SetSprite("sprites_+3");
BonusAnimation();
}
}
IMAGE:
QUESTION:
What would be the best way to set this up for 100 bonuses, instead of writing out each bonus check 100 times.
Thanks so much!
Biting the bullet on this one and I'm just going to plow through the code the hard way.