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 Tobster232 · May 22, 2012 at 07:44 PM · enemyscorepointswhen

Points when an enemy dies.

So following up on my other question about making an enemy drop an item and then once the item is collected the score goes up. However, i would prefer it if when the enemy is destroyed i get points added onto the score, not having to collect something first.

A script would be great however an explination would be just as good.

Thanks in advance for any help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Drakestar · May 22, 2012 at 07:52 PM

The naive (but potentially entirely sufficient) solution to this would be to make the score a static variable somewhere (so that all scripts can easily access it), and simply check whether the enemy health is

The more sophisticated solution would be event-driven. I posted a mini-tutorial that coud easily be adapted in this answer: http://answers.unity3d.com/questions/251765/invoking-all-instances-of-a-non-static-function.html

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
avatar image
0

Answer by BiG · May 22, 2012 at 07:55 PM

You can achieve that in more than a way.

As a first method, I assume that the only way an enemy can be destroied is through a collision with the player (or a projectile shooted by the player, I think you're making a FPS). So, you can attach something like this to the enemy (super-simple example):

 function OnDestroy(){
    score++;
 }

Obviously, this method will give at the player undeserved points, in case that the enemy dies after a collision with an obstacle on the scene, after the level completion...In other words, after a behaviour that doesn't have to give points. Rougly speaking, you have a poor control about points assignment.


Another, more controlled way, would be the assignment of points after a particular collision. An example:

 function OnCollisionEnter (theCollision : Collision) {
    if (theCollision.gameObject.tag == "Ammo"){ //Ammo is just an example
       score++;
       Destroy(gameObject); //this will destroy the enemy!
    }
 }

So, my advice is to implement something similar to this last method. Hope this helps!

Comment
Add comment · Show 3 · 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
avatar image BiG · May 22, 2012 at 07:56 PM 0
Share

Ah, yes: In my simple example, I also assume that the enemies die after one shot. You have to add the control over their life remaining, if they have an health bar.

avatar image xpertboy · Dec 21, 2018 at 10:29 PM 0
Share

when you put score++; won't it just keep adding to infinity?

avatar image Aethenosity xpertboy · Feb 07, 2019 at 08:21 AM 0
Share

Yes, but only one point per kill. It won't keep adding unless you kill an enemy.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a point/score system based on player performance. 2 Answers

Scores/points when you destroy something? 1 Answer

enemies Scoring points killed 0 Answers

how can i destroy a cube when i press a gui button??? 1 Answer

Display var on gui not working... 2 Answers


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