- Home /
Melee system not working
not to long ago i asked how i would i go along making a melee system and i came up with a very basic one here it is:
var Damage = 20;
var stab : AnimationClip;
function OnCollisionEnter(Attack : Collision) {
if(Input.GetButtonDown("Fire1"))
if (Attack.gameObject.tag == "Enemy")
Damage -= 20;
animation.Play("Slash");
}
and when i press fire1 it does not do anything and i dont understand why it is not working please help
for this to work you would need to be ENTERING the collision at the VERY SA$$anonymous$$E FRA$$anonymous$$E that the fire button is being pushed
just change it to function OnCollision (...etc), that should help
That script doesnt make sense to me you shouldnt be checking to see if input is down anyways.
You should play the animation which slashes the sword on the clicking of the mouse button and then OnCollision which should trigger when the sword collides you check to see what you collided with. if you collided with a sword you take whatever damage the sword passes to you (aka its up to the sword to decide the damage dealt or alternately the swords parent if you want the character to have attributes that affect damage) but the enemy shouldnt decide how much damage he takes. Each weapon should have different damages and should pass that damage during a collision.
Basically suedo code
//code attached to player
if(input.getbuttondown("Fire1") { animation.play("Slash"); }
//code attached to things that can be slashed. OnCollision(collider other){
if(collider.gameobject.tag == "Sword") {
//damage given by sword
Health -= collider.gameobject.damage;
// or damage given by swords parent, which is probably the char.
Health -= collider.tranform.parent.gameobject.damage;
}
Your answer

Follow this Question
Related Questions
How do skills affect damage you can do 2 Answers
Melee Combat Script Help 1 Answer
how should i go along making a melee system 1 Answer
Can I make a MMORPG with unity? 20 Answers
Integration with DarkStar/RedDwarf? 1 Answer