- Home /
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
Im BigBob(Felipe) i made a new account sry its an accident
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;
}
}
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);
}
}
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
where do i add this?in the start function or the update function?
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 ._.
Place this script onto ur enemy - and have your Bullet a tag called "Bullet"
Your answer
Follow this Question
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