コード例 #1
0
    void DetectPlayer()
    {
        float distance = Vector3.Distance(transform.position, target.transform.position);

        if (agent.isOnOffMeshLink)
        {
            animator.SetTrigger("jump");
        }
        else
        {
            animator.ResetTrigger("jump");
        }

        if (distance <= lookRadius)
        {
            agent.SetDestination(target.position);
            animator.SetBool("walking", false);
            animator.SetBool("running", true);

            agent.speed = 5;

            if (distance <= agent.stoppingDistance)
            {
                agent.speed = 2;
                animator.SetBool("running", false);

                FaceTarget();

                if (!timer.timerRunning)
                {
                    timer.RestartTimer();
                }
            }
            else
            {
                dealDamage.EndAttack();
            }
        }
        else
        {
            animator.SetBool("running", false);
            animator.SetBool("walking", true);

            agent.SetDestination(direction);
        }
    }