- Home /
Scores/points when you destroy something?
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!
Answer by Novodantis 1 · Aug 21, 2010 at 11:59 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:
var playerScore = 0;
Then in the enemy NPC's death function (for example), add something like:
var thePlayer : GameObject = GameObject.Find("PlayerOne");
// creates a temp variable, then tries to find the player to assign it to that
// (this is messy, there are better ways, but it's easy to get started)
var playerScript: FirstPersonPlayer = thePlayer.GetComponent("FirstPersonPlayer");
// this variable refers to the script attached to the player we found
thePlayer.playerscore += 1;
// within that script, +1 to the score variable
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.
Your answer
Follow this Question
Related Questions
How to create a point/score system based on player performance. 2 Answers
How to run an animation clip on button down-hold? 1 Answer
Heya again guys how about rotation and score board 0 Answers
Points when an enemy dies. 2 Answers
Script Problems 1 Answer