Пример #1
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (controlCharacter.getActualState() != ControlCharacter.State.CROUCH || animator.GetBool("IKActivated"))
        {
            //If c pressed or a ik movement is activated exit of crouch mode
            animator.SetBool("Crouch", false);
        }

        Vector2 input = controlCharacter.getDirection();

        if (input == Vector2.zero)
        {
            if (idleUpdate)
            {
                float animatorIdle = animator.GetFloat("Idle");
                MonoBehaviour.print("update idle:" + animatorIdle + "-" + idleId);
                if (Mathf.Abs(animatorIdle - idleId) > 0.02f)
                {
                    animator.SetFloat("Idle", idleId, idleDamping, Time.deltaTime);
                }
                else
                {
                    idleUpdate = false;
                }
            }
            //MonoBehaviour.print ("time Pass: "******"Idle", 1.0f, idleDamping, Time.deltaTime);
            }
            else
            {
                timePass += Time.deltaTime;
            }
        }
        else
        {
            timePass = 0.0f;
            if (idleId != 0.0)
            {
                idleId     = 0.0f;
                idleUpdate = true;
                animator.SetFloat("Idle", 0.0f, idleDamping, Time.deltaTime);
            }
        }

        animator.SetFloat("Horizontal", input.x, damping, Time.deltaTime);
        animator.SetFloat("Vertical", input.y, damping, Time.deltaTime);
    }
Пример #2
0
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        //Get values of movement
        Vector2 input = controlCharacter.getDirection();

        if (animator.GetBool("IKActivated"))
        {
            //Using Ik animation, disabling other options
            SetIkActivated(animator);
        }
        else
        {
            ControlCharacter.State animatorState = controlCharacter.getActualState();
            if (animatorState == ControlCharacter.State.CHANGE_IDLE)
            {
                //Extra key for change the idle
                timeForLastIdle = originalTimeForLastIdle;
                timeForNextIdle = timeForChangeIdle;
                timePass        = 0.0f;
                changeIdle(animator);
            }
            else if (animatorState == ControlCharacter.State.ACTIVATE_IK)
            {
                iKMovement.startMoving();
            }
            else if (animatorState == ControlCharacter.State.CROUCH)
            {
                animator.SetBool("Crouch", true);
            }
            else if (animatorState == ControlCharacter.State.JUMP)
            {
                animator.SetTrigger("Jump");
            }
            else if (animatorState == ControlCharacter.State.SNEAK)
            {
                if (this.sneakId != 1.0f)
                {
                    setSneaking(animator, true);
                }
                updateAnimatorSneak(animator);
            }
            else
            {
                if (this.sneakId != 0.0f)
                {
                    setSneaking(animator, false);
                }
                updateAnimatorSneak(animator);
            }

            if (input == Vector2.zero)
            {
                //update de idle and face id if necessary
                updateAnimatorIdle(animator);

                //MonoBehaviour.print ("time Pass: "******"Idle", 3.0f, idleDamping, Time.deltaTime);
                    setFaceId(animator, 1.0f);
                }
                else
                {
                    //increases time pass
                    timePass += Time.deltaTime;
                    if (timePass > timeForNextIdle)
                    {
                        //change idle if necessary
                        timeForNextIdle += timeForChangeIdle;
                        changeIdle(animator);
                    }
                }
            }
            else
            {
                //Disable idle on movement
                timePass = 0.0f;
                if (idleId != 0.0)
                {
                    idleId     = 0.0f;
                    idleUpdate = true;
                    animator.SetFloat("Idle", 0.0f, idleDamping, Time.deltaTime);
                    setFaceId(animator, 0.0f);
                }
            }
        }
        animator.SetFloat("Horizontal", input.x, moveDamping, Time.deltaTime);
        animator.SetFloat("Vertical", input.y, moveDamping, Time.deltaTime);
    }