Need some help here. I am not sure how to approach this. My other achievements are much simpler, but this one makes my head spin.
I need something that will start a tracker for each independent kill and if X number are killed in Y seconds (Y is actually static at 10) … then the achievement triggers.
I was looking at IENumerators but couldn’t figure out how to track separately each new kill.
Oh I misread that you want to count results in seconds but that would work as well.
Also you can do this way:
public IEnumerator KilledInTenSeconds(GameObject killedEnemy)
{
yield return new WaitForSeconds(10.0f);
if(killedEnemy==dead) { // don't know how you kill them
// enemy killed in 10 secs
}
}
Sorry title is a little different than what is in the thread, I need to track whether they have killed 10, 50 or 100 in ten seconds. So not just if they have killed 1 object but 10, 50 or 100 of them in ten seconds. Ill change the title a little. Sorry for the confusion.
I’m not sure about your game but you can do for example like Diablo 3 does. You need to count your kills every let’s say 3sec and check if your killed enemy count have increased if yes then keep counting time elapsed and killed amount if 3 seconds passed and your enemy count is the same as it was last time (3 secs before) then reset your counter and collect results: you will have results: enemies killed and time elapsed.
I would just track combokills or something and fire a 10 sec timer every time combokills = 1
Have a function looking for combokill numbers as they build up over the ten sec period to fire something to playerprefs or however your handling that to turn on achievement.
Then when the timer hits 0 reset combokills to 0 and the process restarts.
How about:
List of floats
every time you get a kill, add Time.time to the list
If list[0] is less than Time.time - 5 seconds, removeAt(0)
if list.count > Acheiement, give it.