Example #1
0
    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);
    }
Example #2
0
 public void MoveUp()
 {
     aiBase.rb2d.velocity = Vector2.up * aiBase.speed;
     aiBase.direction     = up;
     aiBase.UpdateAnimatorState(AnimatorStateEnum.walkUp);
 }