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 twinmoon1 · Oct 15, 2013 at 11:14 AM · multipledamageenemies

how do i kill multiple enemies?

I have a script for my enemy health and a script to do damage to him. However if I have multiple enemies the bullets will do damage and kill only one of them and just pass right through the rest of them. Please tell me what I am doing wrong. here is the bullet damage script followed by the health script.

 var damage: float = 5.0;
 var ApplyDamage : Drone_health;
 
 function OnTriggerEnter (other : Collider) {
 if(other.gameObject.CompareTag("Enemy"))
     print("ow!");
     ApplyDamage(damage);
 }
 
 @script AddComponentMenu("Environment Props/DamageTrigger")
 
  Health script
 var health: float = 10.0;
 function ApplyDamage(damage: float){
     
     health -= damage;
     
     
     //check health and call Die if need to
     if(health <= 0){
         health = 0; //for GUI
         Die();    
     }
 
 }
 function Die(){
     
     print("dead!");
     Destroy (gameObject);
     }    
Comment
Add comment · Show 5
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 mattssonon · Oct 15, 2013 at 11:42 AM 0
Share

How are you setting var ApplyDamage : Drone_health;? Usually you would set the target of a trigger action inside OnTriggerEnter (other : Collider) using the collider.

avatar image twinmoon1 · Oct 16, 2013 at 12:07 AM 0
Share

what do you mean "How are you setting var ApplyDamage : Drone_health;? " I am not sure I understand what you are asking? could you please explain it to me in terms I can understand.

avatar image mattssonon · Oct 16, 2013 at 07:21 AM 0
Share

What is Drone_health? A script? If so, please show some code from it.

avatar image pako · Oct 16, 2013 at 08:41 AM 0
Share

Hi @twinmoon,

I really don't understand what the info you give. You say "here is the bullet damage script followed by the health script", so I expect to find 2 scripts (1 for Damage and 1 for Health), but you only provide 1 script containing 30 lines!

Additionally, in line 2 you declare the variable ApplyDamage of type Drone_health and you don't supply the code for the Drone_health script either (what@mattssonon is also asking). I mean it's not like ApplyDamage is of a known type like int or string, so how can we know what it stands for if you don't give the relevant code for it?

Last but not least, you are not clear enough about which game object each of these scripts is attached to. Do you actually have bullet objects with a script flying around doing damage? And if so, are these bullet objects actually necessary for the game? Because I would personally use raycasting to effect the damage of a bullet on an enemy.

We are all volunteers trying to help, but if you don't give enough information it's like you don't want to be helped.

avatar image mattssonon · Oct 16, 2013 at 08:44 AM 0
Share

@pako - I think the health script starts where he wrote "Health script" on line 12.

0 Replies

· Add your reply
  • Sort: 

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

16 People are following this question.

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

Related Questions

Trouble with apply damage to enemy 2 Answers

Multiple enemies not working 1 Answer

how to make enemies have health and get damaged by bullets 3 Answers

How to use multiple Colliders for an enemy to detect multiple collisions in different areas to determine the damage to the enemy? I.E. Headshot etc. 1 Answer

Changing the Slider.value cause a lag problem in an Android device. 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