Hi, im trying to make a FPS game which you battle some AI controlled NPCs. I need a script that can help accumulate points when i kill the NPC. Any help? thanks!
asked Aug 21 '10 at 10:30 AM
The abstract principle of this is very simple; it's mostly down to how you want to implement it. Basically you need to store a variable, Score, and each time an enemy is killed, increment that by one.
You could add the variable to the player object, or have an EmptyGameObject which holds stats and such, but the method is mostly the same. Say we add it to our player, called PlayerOne, which has a script called FirstPersonPlayer. In that script, add:
Then in the enemy NPC's death function (for example), add something like:
That should hopefully be a good starting point, but you could make it better. For example, instead of playerScore += 1, you could have a variable in the enemy called "points" containing the score value of that NPC, and then change that last line to playerScore += points.
answered Aug 21 '10 at 11:59 AM