public void LookAt(GameObject obj) { double distanceX = Mathf.Abs(aiBase.posX - obj.transform.position.x); double distanceY = Mathf.Abs(aiBase.posY - obj.transform.position.y); //prefer more dominant axis if (distanceX > distanceY) { //it is on my left if (obj.transform.position.x < aiBase.posX) { aiBase.direction = aiBase.left; aiBase.UpdateAnimatorState(AnimatorStateEnum.walkLeft); } else { aiBase.direction = aiBase.right; aiBase.UpdateAnimatorState(AnimatorStateEnum.walkRight); } } else { //it is below me if (obj.transform.position.y < aiBase.posY) { aiBase.direction = aiBase.down; aiBase.UpdateAnimatorState(AnimatorStateEnum.walkDown); } else { aiBase.direction = aiBase.up; aiBase.UpdateAnimatorState(AnimatorStateEnum.walkUp); } } //UpdateAnimatorState(AnimatorStateEnum.stop); }
public void MoveUp() { aiBase.rb2d.velocity = Vector2.up * aiBase.speed; aiBase.direction = up; aiBase.UpdateAnimatorState(AnimatorStateEnum.walkUp); }