Esempio n. 1
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);
    }
Esempio n. 2
0
 void OnMouseDown()
 {
     avatar.startMoving();
 }