public override void Interact()
    {
        if (agent.IsArrived(transform.position, Destination.position))
        {
            return;
        }

        if (agent.enabled)
        {
            agent.isStopped = false;
        }
        else
        {
            agent.isStopped = false;
            agent.enabled   = true;
        }

        if (carryingCoroutine != null)
        {
            StopCoroutine(carryingCoroutine);
        }
        carryingCoroutine = StartCoroutine(GetInPosition());

        IEnumerator GetInPosition()
        {
            agent.SetDestination(Destination.position);
            while (!agent.IsDone())
            {
                yield return(null);
            }
            agent.enabled = false;
        }
    }
Example #2
0
    public override void Interact()
    {
        if (destinationRoutine != null)
        {
            StopCoroutine(destinationRoutine);
        }

        agent.enabled      = true;
        destinationRoutine = StartCoroutine(GetInPosition());

        IEnumerator GetInPosition()
        {
            (FindObjectOfType(typeof(PikminManager)) as PikminManager).StartIntetaction(this);

            agent.avoidancePriority = 50;
            agent.isStopped         = false;
            agent.SetDestination(destination.Point());
            yield return(new WaitUntil(() => agent.IsDone()));

            agent.enabled    = false;
            collider.enabled = false;

            (FindObjectOfType(typeof(PikminManager)) as PikminManager).FinishInteraction(this);

            //Delete UI
            if (fractionObject != null)
            {
                Destroy(fractionObject);
            }

            //Capture Animation
            float    time = 1.3f;
            Sequence s    = DOTween.Sequence();

            s.AppendCallback(() => destination.StartCapture());
            s.Append(objectRenderer.material.DOColor(captureColor, "_EmissionColor", time));
            s.Join(transform.DOMove(destination.transform.position, time).SetEase(Ease.InQuint));
            s.Join(transform.DOScale(0, time).SetEase(Ease.InQuint));
            s.AppendCallback(() => destination.FinishCapture());
            s.Append(destination.transform.DOPunchScale(-Vector3.one * 35, .5f, 10, 1));
        }
    }
Example #3
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;
        }
    }