Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user-3061 (yahoo) · Aug 21, 2010 at 10:30 AM · fpsscorepoints

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges