How to structure achievements?
Hi,
I would like to create an achievement system in the game where you have groups of achievements, collect a of x, b of x, a of y, b of y, etc. where a and b are floats and x and y are scores types which I am recording in a singleton. There are also unique achievements that check for totally unique conditions. Each achievement has an Id, a string name, a GameObject and a sprite associated with it, a boolean recording if the condition was triggered or not, and a position in the menu depending on its ID.
I did create the system using arrays, where images, GOs, names etc. are in their own arrays. Several different for loops check for different types of achievements each frame, one for loop checks if a, b, c... (these are in their own arrays) is true for x, another if it's true for y, etc. Depending on if it's true GOs get triggered, sprites displayed, strings passed to Texts.
It works, however the whole thing seems confusing. Many arrays (I should have used lists anyway, I don't have a set amount of achievements), several for loops... My question is, what would be the efficient way of doing this? I will restructure from arrays to lists anyway, but would let's say creating an achievement class that checks the bool list prove to be useful?
Answer by tormentoarmagedoom · Aug 31, 2018 at 11:58 AM
Good day.
I think they way you doing is a correct and efficient way. Maybe if there are several iterations of if senteces, you could o it in a corrutine to check obly 1 iteration each frame to reduce cpu consumption, but as I said, the way you do it is nice.