/// <summary>
 /// Focus를 해제한다.
 /// </summary>
 private void RemoveFocus()
 {
     if (focus != null)
     {
         Debug.Log("focus는 null이 아니다.");
         focus.OnDefocused();
     }
     focus = null;
     motor.StopFollowingTarget();
 }
    /// <summary>
    /// Focus를 설정한다.
    /// </summary>
    /// <param name="newFocus">Focus 대상</param>
    private void SetFocus(MORPG_Interactable newFocus)
    {
        if (newFocus != focus)
        {
            if (focus != null)
            {
                focus.OnDefocused();
                focus = newFocus;
                motor.FollowTarget(newFocus);
            }
        }

        focus = newFocus;
        newFocus.OnFocused(transform);
        motor.FollowTarget(newFocus);
    }
    // Update is called once per frame
    void Update()
    {
        // TODO (장현명) : Test 후 리펙토링
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Click screen
        if (Input.GetButtonDown("MORPG_Fire1"))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // Click ground
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.CompareTag("MORPG_Npc"))
                {
                    Debug.Log("Npc");
                    MORPG_Interactable interactable = hit.collider.GetComponent <MORPG_Interactable>();

                    if (interactable != null)
                    {
                        Debug.Log("interactable은 null이 아니다");
                        SetFocus(interactable);
                    }
                    else
                    {
                        Debug.Log("interactable은 null이다.?");
                        RemoveFocus();
                    }
                }
                if (hit.transform.CompareTag("MORPG_Ground"))
                {
                    //Debug.Log("Ground");
                    mouseClickParticle.UseObject(hit.point);
                    motor.MoveToPoint(hit.point);
                    RemoveFocus();
                }
                if (hit.transform.CompareTag("MORPG_Monster"))
                {
                    motor.MoveToPoint(hit.point);

                    MORPG_Interactable    interactable    = hit.collider.GetComponent <MORPG_Interactable>();
                    MORPG_EnemyController enemyController = hit.collider.GetComponent <MORPG_EnemyController>();
                    MORPG_CharacterStats  enemyStats      = hit.collider.GetComponent <MORPG_CharacterStats>();
                    if (interactable != null)
                    {
                        SetFocus(interactable);
                        combat.Attack(enemyStats, stats.damage);
                    }

                    else
                    {
                        RemoveFocus();
                    }
                    Debug.Log("Monster");
                }
            }


            // LayerMask를 이용한 코드

            //// Click ground
            //if (Physics.Raycast(ray, out hit, movementMask))
            //{
            //    //Debug.Log("movementMask : " + movementMask.value);
            //    mouseClickParticle.UseObject(hit.point);
            //    motor.MoveToPoint(hit.point);
            //    RemoveFocus();
            //}

            //// Click monster
            //if(Physics.Raycast(ray,out hit, monsterMask))
            //{
            //    //Debug.Log("monsterMask : " + monsterMask.value);
            //}
            //// Click npc
            //if (Physics.Raycast(ray, out hit, npcMask))
            //{
            //    //Debug.Log("npcMask : " + npcMask.value);
            //    MORPG_Interactable interactable = hit.collider.GetComponent<MORPG_Interactable>();

            //    if (interactable != null)
            //    {
            //        Debug.Log("interactable은 null이 아니다");
            //        SetFocus(interactable);
            //    } else
            //    {
            //        Debug.Log("interactable은 null이다.?");
            //        RemoveFocus();
            //    }
            //}
        }
    }
Exemple #4
0
 /// <summary>
 /// 타겟을 따라다닌다.
 /// </summary>
 /// <param name="newTarget">새로운 타겟</param>
 public void FollowTarget(MORPG_Interactable newTarget)
 {
     agent.stoppingDistance = newTarget.radius * 0.8f;
     agent.updateRotation   = false;
     targetTransform        = newTarget.interactionTransform;
 }