I want to add some melee attacking to my game. I know how to use melee attack but when I know who is the enemy and I don’t in front of him.
First thing in melee attacks I need to pull out my sword so I’ll be able to attack. I made an animation for that (grab the sword and pull) but I don’t know how to pull the sword out. If I don’t wrong you need attach the sword to the bone in the hand while the animation is play (correct me if I’m wrong). How I can pull in and out the sword? (The sword is not attach to anything, don’t have rigidbody and I don’t have any code for that).
After I pull my sword out I need to attack. The melee attacks I did before was that only the enemy able to do melee attack (works perfect) but now I want me to do that.
This is the part of the enemy’s melee code:
function Attack ()
{
if (canAttack)
{
if (ableMove)
{
animation.Play("Stop");
yield WaitForSeconds (0.3);
attackTest = true;
ableMove = false;
}
if (attackTest)
{
animation.Play("Hit");
CharacterControl.healthBarDisplay -= 0.1;
canAttack = false;
yield WaitForSeconds (coolDown);
canAttack = true;
}
}
}
(That code works fine) If I attach that code to my character it will work also but not when I fase to the enemy and when I fight against enemy that not defined as my target. (It works with the enemy because he always look at me and I am he’s only target…). How I can do melee attacks when I fase an enemy? (I don’t care how much enemys, if there is an enemy in front of me and close to me - he loss health). If I don’t wrong you need to use tags (correct me again if it wrong).
Sorry for poor english.