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 BigBlob · Jul 29, 2012 at 04:22 PM · collisionbulletenemyailife

Kill a Enemy - Answer

Very simple question that is solved by myself so if anyone want to use this code, feel free.

 var life = 0;
 
 function OnCollisionEnter(boom : Collision) {
 
     if(boom.gameObject.tag == "bullet")
     {
            life +=1;
            if(life == 50)
            Destroy(gameObject);
     }
     }

Make your weapon that hits the enemy have a tag "Bullet". And then attach this script to your Enemy. You can change the Life == 50 to 25 to kill enemy faster or the Life +=1 to 5

THIS IS AN ANSWER C#

  • Felipe

Comment
Add comment · Show 3
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 SrBilyon · Aug 11, 2012 at 07:16 AM 2
Share

This is in Javascript, your post says this is C#.

avatar image SmokeTear · Sep 08, 2012 at 04:46 PM 0
Share

Im BigBob(Felipe) i made a new account sry its an accident

avatar image $$anonymous$$ · Jul 16, 2018 at 06:46 PM 0
Share

The script doesn't work I don't $$anonymous$$now why , and there's no errors , Is that because im making an axe, I just i want it if she toche the enemy he will die. any help? :( I have edit the script so that's it :

var compo : GameObject;

function OnCollisionEnter(boom : Collision) {

  if(boom.gameObject.tag == "AXE")
  {
       compo.GetComponent("Animator").enabled = false;  
  }
  }

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by SrBilyon · Aug 11, 2012 at 07:18 AM

C# Version of the above code

   public int life = 0;
     
     public void OnCollisionEnter(Collision boom) 
     {
         //If the object that triggered this collision is tagged "bullet"
         if(boom.gameObject.tag == "bullet")
         {
                life +=1;
                if(life == 50)
                Destroy(gameObject);
         }
     }
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 SmokeTear · Sep 08, 2012 at 04:47 PM 0
Share

Hey I accidentaly wrote that my Script is in C# but its in JS - Also SmokeTear is my Profile meaning that im BigBlob(Felipe) but thanks anyways

avatar image M-Mahad · Jul 22, 2016 at 01:25 AM 0
Share

where do i add this?in the start function or the update function?

avatar image
-1

Answer by Sky550 · Apr 06, 2013 at 12:47 PM

I have a weapon that shoots and deals damage but i dragged script on a target bt it doesn't die when i shoot anyway ._.

Comment
Add comment · Show 1 · 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 DryTear · May 05, 2013 at 07:54 PM 0
Share

Place this script onto ur enemy - and have your Bullet a tag called "Bullet"

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

12 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

Related Questions

Enemy shooting player driving me crazy! 2 Answers

Optimization of bullet hit calculation per frame 1 Answer

Create Bullethole with onCollisionEnter 2 Answers

Destroy bullet on random collision 2 Answers

Hit enemy life 0 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