// Update is called once per frame void Update() { CheckTarget(); if (target != null) { Vector3 otherPos = target.transform.position; Vector3 myPos = transform.position; destination = otherPos + (myPos - otherPos).normalized * (range - 1f); //attack if (Vector3.Distance(otherPos, myPos) <= range) { mc.atkDirection = (otherPos - myPos).normalized; mc.AttackAttempt(); } //walking around if (Vector3.Distance(destination, myPos) < 1f) { //close enough. attack! //Debug.Log(string.Format("{0} attacking", name, destination)); //strafing if (strafer) { if (leftHanded) { mc.MoveTowards(-transform.right); } else { mc.MoveTowards(transform.right); } } } else { //Debug.Log(string.Format("{0} moving to {1}", name, destination)); //move towards destination mc.MoveTowards(destination - myPos); } mc.transform.LookAt(target.transform); } }