- Home /
How do I make my melee script do damage.
I have a melee script but I don't know how to make it do damage to either an ai or a player here is the script so far it is in js.
var target : Transform;
function Update () { var dist : float = Vector3.Distance(transform.position, target.position);
if(Input.GetKeyUp(KeyCode.Mouse0) && dist <= 2.1){
GetComponent.<Animation>().Play("Default Take");
}
if(Input.GetKeyUp(KeyCode.Mouse0) && dist > 2.1){
GetComponent.<Animation>().Play("Default Take");
}
}
Answer by YoungDeveloper · Jul 28, 2015 at 04:19 AM
Create a script which will hold npc health
When attack is done check if you actually hit the target. You could use collision check, distance, trigger or raycasts.
When damage is done, use GetComponent from hit object - npc script and remove the damage done from its health. If health equals or is lower than 0 kill the npc.
Your answer
Follow this Question
Related Questions
hold key unequip sword 0 Answers
Melee Damage script by collision 2 Answers
Hitting Multiple Enemies 1 Answer
Melee system script help 1 Answer
noob question about melee combat 1 Answer