//should be called whenever our target is within range public virtual void Attack() { var closest = FindClosestConstruct(); if ((closest.transform.position - transform.position).sqrMagnitude <= Mathf.Pow(attackRange, 2)) { animator.Play("HostileAttack"); Construct constructScript = closest.GetComponent <Construct>(); if (constructScript != null) { constructScript.Damage(attackDamage); Debug.Log("hit " + closest.name); } } //make sprite face the right way //should only need to be called when target changes! bool isLeft; if (ai.velocity.x == 0) { isLeft = sprite.flipX; } else if (ai.velocity.x < 0) { isLeft = true; } else { isLeft = false; } sprite.flipX = isLeft; }