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
3
Question by FPSNOOB:D · Nov 01, 2012 at 05:49 AM · fpsdamagebulletsenemies

how to make enemies have health and get damaged by bullets

i need a code that will make my enemies get damaged when they are hit by my bullets. I have not put health or anything on the yet apart from a collider.

Comment
Add comment · Show 4
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 deltamish · Nov 01, 2012 at 09:28 PM 0
Share

what type of bullets are you using in your gun RayCast or instantiated bullets

avatar image FPSNOOB:D · Nov 02, 2012 at 08:00 AM 0
Share

Instatiate

avatar image Fluffin · Jan 06, 2015 at 06:21 AM 0
Share

it will not destroy the object. i added the Destroy script and has not worked i have correctly placed the codes and tagged the objects. any help? thanks

avatar image JohastHart · May 04, 2016 at 12:29 PM 0
Share

Hey. I know I am a bit late but I did everything right and I got no errors but the collider doesn't do anything. srry for bad english btw.(If it's bad)

3 Replies

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

Answer by deltamish · Nov 02, 2012 at 11:13 AM

Hi, May i suggest you to use raycastgun because it is way better and you can add penetration too

Heres is the damage script

 var health:float = 90;
 
 function Damage(dmg:float){
 health -= dmg;
 }
 
 function Update (){
 if(health <=0){
 //add your death code
 }
 
 }

Add this code to your bullet

 var dmg:float = 20;
 
 function OnTriggerEnter(hit:Collider){
 if(hit.tag == "Enemy"){
 hit.transform.SendMessage("Damage",dmg);
 }
 
 }

assign the tag Enemy to the object you added the Damage script

Comment
Add comment · Show 5 · 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 lordrockit · Sep 15, 2013 at 08:23 PM 0
Share

thanks now how would i make the entity i shoot go ragdoll

avatar image TheReclaimer117 · Feb 01, 2014 at 09:06 AM 0
Share

what death code should i use? what is the death code? can you post one?

avatar image KingFerretDino · Aug 22, 2016 at 10:22 PM 0
Share

@deltamish I tried this, but I get the error : Send$$anonymous$$essage BulletDamage has no receiver!

avatar image KingFerretDino KingFerretDino · Aug 22, 2016 at 10:22 PM 0
Share

All I did was change the variable names, I changed em back and same error

avatar image FriendlyFPSCreator · Aug 23, 2016 at 11:45 PM 0
Share

Thanks a million! Deltamish and jrocker2002 your the best!

avatar image
2

Answer by skiedude · Aug 23, 2016 at 06:26 AM

I'd also look into https://unity3d.com/learn/tutorials/projects/survival-shooter-tutorial its a follow along tutorial by Unity a couple years ago (check the attached PDF in the assets for specific unity 5 updates) and it goes over setting playerhealth/enemy health and taking damage.

Has some good starter scripts to look at as well.

Comment
Add comment · Show 2 · 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 FriendlyFPSCreator · Aug 23, 2016 at 11:41 PM 0
Share

Thanks! You have helped an 11 year old learn to script (me). I have been using unity for 4 years now ever since I was 7 and it's awesome. It's people like you who always help me learn more!

avatar image SoldierofYHVH FriendlyFPSCreator · Aug 08, 2017 at 12:44 AM 0
Share

Wow! You speak and act so maturely. I hope you keep at what you're doing!

avatar image
0

Answer by Jrocker2002 · Mar 03, 2014 at 03:58 AM

To do a death code use this

if(health <= 0) { //Play a death anim or

}

Comment
Add comment · Show 2 · 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 Jrocker2002 · Mar 03, 2014 at 03:58 AM 0
Share

type in Destroy(gameObject);

avatar image matthewjparker99 · May 16, 2015 at 10:46 PM 1
Share

BEST HEALTH AND DA$$anonymous$$AGE SCRIPT I HAVE EVER SEEN THAN$$anonymous$$S deltamish AND Jrocker2002!!!!!!

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

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

Related Questions

Bullets kill enemy... but continue to travel? 1 Answer

Bullet not destroying on collision 1 Answer

A node in a childnode? 1 Answer

spraying bullets 3 Answers

Preventing Rapid Fire 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