Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.Find("Player");
        InvokeRepeating("Trace", 0, 1.0f);        //방향전환1초마다
        MonsterClass.GetInstance().enemys.Add(this);

        animator.SetTrigger("Walk");
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))   //마우스 좌측 버튼을 누름.
        {
            bool attackStart = false;
            clickPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            foreach (var enemy in MonsterClass.GetInstance().enemys)
            {
                if (Vector2.Distance(enemy.transform.localPosition, clickPosition) < 1.0f)
                {
                    if (Vector2.Distance(enemy.transform.position, transform.position) < 2.0f)
                    {
                        attackStart = true;
                        break;
                    }
                }
            }

            if (attackStart)
            {
                eState = STATE.ATTACK;

                animator.SetTrigger("Attack");
            }


            eState = STATE.WALK;

            animator.SetTrigger("Walk");
            if (clickPosition.x < transform.position.x)
            {
                transform.localScale = new Vector3(-1, 1, 1);
            }
            else
            {
                transform.localScale = new Vector3(1, 1, 1);
            }
        }
        if (eState == STATE.WALK)
        {
            float dis = Vector2.Distance(transform.position, clickPosition);
            if (dis <= 0.01f)               //클릭한 지점에 다왔다면
            {
                eState = STATE.IDLE;
                animator.SetTrigger("Idle");
                clickPosition = Vector3.zero;
            }
        }
    }