Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     position2D.x       = this.transform.position.x;
     position2D.y       = this.transform.position.z;
     player             = GameObject.FindGameObjectWithTag("Player");
     animator           = gameObject.GetComponent <Animator>();
     navMeshAgent       = GetComponent <NavMeshAgent>();
     navMeshAgent.speed = walkSpeed;
     toPositionIndex    = initIndex;
     mode = initMode;
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //2d座標更新
        position2D.x = this.transform.position.x;
        position2D.y = this.transform.position.z;

        //行動
        switch (mode)
        {
        case ENEMY_MODE.STAND:
            animator.SetBool("LookAround", true);
            animator.SetBool("Run", false);
            animator.SetBool("Walk", false);
            navMeshAgent.isStopped = true;
            targetPosition         = this.transform.position;
            if (navMeshAgent.pathStatus != NavMeshPathStatus.PathInvalid)
            {
                navMeshAgent.SetDestination(targetPosition);
            }
            //発見
            if (findPlayer)
            {
                navMeshAgent.isStopped = false;
                priviousMode           = mode;
                mode = ENEMY_MODE.CHASE;
            }
            break;

        case ENEMY_MODE.PATROL:
            animator.SetBool("Walk", true);
            animator.SetBool("Run", false);
            animator.SetBool("LookAround", false);
            Patrol();
            if (findPlayer)
            {
                priviousMode = mode;
                mode         = ENEMY_MODE.CHASE;
            }
            break;

        case ENEMY_MODE.CHASE:
            animator.SetBool("Run", true);
            animator.SetBool("LookAround", false);
            animator.SetBool("Walk", false);
            Chase();
            if (!findPlayer)
            {
                mode = priviousMode;
            }
            break;
        }
    }