示例#1
0
    void Update()
    {
        //상태 겟셋을 알기 위해서 넣은 에너미 변수
        AnimalAI ai = GetComponent <AnimalAI>();

        if (ai.GetAnimalType() == AnimalAI.AnimalType.Natural)
        {
            //적 캐릭터가 이동중일 때만 회전한다.
            if (agent.isStopped == false)
            {
                //NavMeshAgent가 가야할 방향 백터를 쿼터니언 각도로 변환
                Quaternion rot = Quaternion.LookRotation(agent.desiredVelocity);

                //보간함수를 사용하여 점진적을 회전시킵니다.
                animalTr.rotation = Quaternion.Slerp(animalTr.rotation
                                                     , rot, Time.deltaTime * damping);
            }

            //순찰상태가 아니라면 바로 빠져나와라.
            if (!isPatrolling)
            {
                return;
            }

            //NavMeshAgent가 이동하고 있고 목적지에 도착했는지 여부를 계산.
            if (agent.velocity.sqrMagnitude >= 0.2f * 0.2f && agent.remainingDistance <= 0.5f)
            {
                nextIdx = Random.Range(0, wayPoint.Count);
                MoveWayPoint();
            }
        }
    }