Пример #1
0
    void CheckInteraction()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, 1f);

        if (colliders.Length == 0)
        {
            return;
        }

        foreach (Collider collider in colliders)
        {
            if (collider.GetComponent <InteractiveObject>() && collider.GetComponent <NavMeshAgent>().enabled)
            {
                objective = collider.GetComponent <InteractiveObject>();
                objective.AssignPikmin();
                StartCoroutine(GetInPosition());

                break;
            }
        }

        OnEndThrow.Invoke(0);

        IEnumerator GetInPosition()
        {
            isGettingIntoPosition = true;

            agent.SetDestination(objective.GetPositon());
            yield return(new WaitUntil(() => agent.IsDone()));

            agent.enabled = false;
            state         = State.Interact;

            if (objective != null)
            {
                transform.parent = objective.transform;
                transform.DOLookAt(new Vector3(objective.transform.position.x, transform.position.y, objective.transform.position.z), .2f);
            }

            isGettingIntoPosition = false;
        }
    }