So, I have a problem and I don’t know how to write this:
I have two weapons, a switchblade and a sword. What I want to do for the enemy is to detect when either one is swinging a sword for it to dodge. Unfortunately, I don’t know how to write that.
var swordPlay = GameObject.Find("blade").transform.parent.GetComponent(WepProperty).isAttacking; //I have two "blades", so this variable will only get one. When I swing one of the weapons, it's own WepProperty script isAttacking variable will turn true.
//I'm not sure how I could play GameObject.FindGameObjectsWithTag() into this dilemma because I'll need to use a for() statement and i don't think it would be a good idea to do so, unless if you know how to make it work well
//I have variables already defined also, and you don't need to check the script for errors
if(!swordPlay || (swordPlay && range >= backrange)){ //approaching player
transform.LookAt(player.transform);
var moveDirection:Vector3 = transform.TransformDirection(0,0,1);
moveDirection.y -= gravity;
controller.Move(moveDirection*Time.deltaTime*speed);
db = 0;
}
else if(swordPlay && range <= backrange && relativePoint.z > 0.0){ //dodging player when he swings his weapons
transform.LookAt(player.transform);
var backwards:Vector3 = transform.TransformDirection(randomdodge);
backwards.y -= gravity;
controller.Move(backwards*Time.deltaTime*speed);
}