Ejemplo n.º 1
0
    private void AnimationUpdate()
    {
        if (agent.remainingDistance <= 0.05f)
        {
            isWalking   = false;
            ps.directed = false;
        }
        else
        {
            isWalking = true;
        }
        anim.SetBool("walking", isWalking);

        if (!isWalking)
        {
            switch (state)
            {
            case animState.idle:
                anim.SetBool("sitting", false);
                anim.SetBool("eating", false);
                anim.SetBool("sleeping", false);
                anim.SetBool("drinking", false);
                break;

            case animState.sitting:
                anim.SetBool("sitting", true);
                anim.SetBool("eating", false);
                anim.SetBool("sleeping", false);
                anim.SetBool("drinking", false);
                break;

            case animState.eating:
                anim.SetBool("sitting", true);
                anim.SetBool("eating", true);
                anim.SetBool("sleeping", false);
                anim.SetBool("drinking", false);
                ps.eat();
                break;

            case animState.sleeping:
                anim.SetBool("sitting", false);
                anim.SetBool("eating", false);
                anim.SetBool("sleeping", true);
                anim.SetBool("drinking", false);
                break;

            case animState.drinking:
                anim.SetBool("sitting", false);
                anim.SetBool("eating", false);
                anim.SetBool("sleeping", false);
                anim.SetBool("drinking", true);
                ps.drink();
                break;
            }
        }
        else
        {
            anim.SetBool("sitting", false);
            anim.SetBool("eating", false);
            anim.SetBool("sleeping", false);
            anim.SetBool("drinking", false);
        }

        if (state == animState.idle)
        {
            if (UnityEngine.Random.Range(0, 10000) < sleepChance)
            {
                state = animState.sleeping;
            }
            else if (UnityEngine.Random.Range(0, 10000) < sitChance)
            {
                state = animState.sitting;
            }
        }
        else if (state == animState.sleeping)
        {
            if (UnityEngine.Random.Range(0, 10000) < idleChance)
            {
                state = animState.idle;
            }
        }
        else if (state == animState.sitting)
        {
            if (UnityEngine.Random.Range(0, 1000) < idleChance)
            {
                state = animState.idle;
            }
        }

        if (state != animState.drinking && state != animState.eating && !ps.directed)
        {
            if (UnityEngine.Random.Range(0, 1000) < moveChance)
            {
                Vector3 newPos = new Vector3(UnityEngine.Random.Range(-10, 10), 0, UnityEngine.Random.Range(-10, 10));
                ps.SetDestination(newPos, false);
            }
        }
    }