Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (state == npcStates.playing && simonRunning == false)
        {
            StartCoroutine(simonGameco);
        }

        if (state == npcStates.look || (state == npcStates.done && doneCantSeePlayer == true))
        {
            float   lerpanglef = Mathf.LerpAngle(transform.eulerAngles.y, newAngle, 0.125f);
            Vector3 lerpangle  = new Vector3(transform.eulerAngles.x, lerpanglef, transform.eulerAngles.z);
            transform.eulerAngles = lerpangle;
        }

        if (simonRunning == true)
        {
            up    = Input.GetKeyDown(KeyCode.UpArrow);
            down  = Input.GetKeyDown(KeyCode.DownArrow);
            left  = Input.GetKeyDown(KeyCode.LeftArrow);
            right = Input.GetKeyDown(KeyCode.RightArrow);
        }


        if (Input.GetKeyDown(KeyCode.Space) && state == npcStates.playing)
        {
            //Debug.LogWarning(state);
            state = npcStates.done;
        }
    }
Exemple #2
0
    void SetAnimatorState(npcStates npcState, bool state, bool disableOthers)
    {
        if (disableOthers)
        {
            _Animator.SetBool("Patrol", false);
            _Animator.SetBool("isRunning", false);
            _Animator.SetBool("isWalking", false);
            _Animator.SetBool("isAttacking", false);
        }

        switch (npcState)
        {
        case npcStates.Patrol:
            _Animator.SetBool("Patrol", state);
            break;

        case npcStates.Walk:
            _Animator.SetBool("isWalking", state);
            break;

        case npcStates.Run:
            _Animator.SetBool("isRunning", state);
            break;

        case npcStates.Attack:
            _Animator.SetBool("isAttacking", state);
            break;
        }
    }
Exemple #3
0
    void FixedUpdate()
    {
        float distToPlayer = Vector3.Distance(transform.position, player.transform.position);

        Vector3 toVector      = player.transform.position - transform.position;
        float   angleToPlayer = Vector3.Angle(transform.forward, toVector);

        switch (state)
        {
        // NPC is looking for player. Once found switches to follow state.
        case npcStates.look:


            //
            if (distToPlayer < AwareDistance)
            {
                playAwarenessNoise();
                state = npcStates.follow;
            }


            if (angleToPlayer < LookAngle)
            {
                if (distToPlayer < LookDistance)
                {
                    if (canSeePlayer())
                    {
                        playAwarenessNoise();
                    }
                    state = npcStates.follow;
                }
            }


            break;

        // NPC is following player
        case npcStates.follow:
            if (audio.isPlaying == false)
            {
                audio.PlayOneShot(walking);
            }

            navmesh.enabled = true;
            navmesh.SetDestination(player.transform.position);
            if (distToPlayer < ConversationDistance)
            {
                navmesh.enabled = false;
                state           = npcStates.talk;
            }

            break;

        case npcStates.talk:
            audio.Stop();


            // We need to check if the player is engaged and wait.
            if (pc.isEngaged)
            {
                break;
            }


            bubble.gameObject.SetActive(true);
            pc.engagePlayer(this.gameObject);
            state = npcStates.playing;
            break;

        case npcStates.playing:

            if (simonDone == true)
            {
                state = npcStates.done;
            }
            break;

        case npcStates.done:

            bubble.gameObject.SetActive(false);
            if (canSeePlayer())
            {
                transform.LookAt(player.transform);
                doneCantSeePlayer = false;
            }
            else
            {
                doneCantSeePlayer = true;
            }
            break;
        }
    }