コード例 #1
0
ファイル: Player.cs プロジェクト: ylyking/AnimatorAccess
        void OnIdle(AnimatorAccess.StateInfo info, AnimatorAccess.LayerStatus status)
        {
            float random = Random.value;

            if (random > YawnThreshold)
            {
                // start yawning from time to time which will block input
                anim.SetYawnTrigger();
            }
            if (Time.realtimeSinceStartup - randomRotationTimestamp > randomRotationInterval)
            {
                // rotate after randomRotationInterval to random direction
                int currrentRotation = anim.GetRotate();
                int newRotation      = currrentRotation == 0 ? (int)Mathf.Sign((int)Random.Range(-1, 1)) : 0;
                anim.SetRotate(newRotation);
                randomRotationTimestamp = Time.realtimeSinceStartup;
            }
        }
コード例 #2
0
 void FixedUpdate()
 {
     previousState0 = currentState0;
     currentState0  = animator.GetCurrentAnimatorStateInfo(0).nameHash;
     if (anim.IsYawning(currentState0))
     {
         // input is suppressed on yawning
         speed = 0f;
         if (currentState0 != previousState0)
         {
             // just entered yawning state, play sound
             Debug.Log("Yawning state entered");
             audio.Play();
         }
         return;
     }
     else if (anim.IsIdle(currentState0))
     {
         float random = Random.value;
         if (random > YawnThreshold)
         {
             // start yawning from time to time which will block input
             anim.SetYawnTrigger();
         }
         if (Time.realtimeSinceStartup - randomRotationTimestamp > randomRotationInterval)
         {
             // rotate after randomRotationInterval to random direction
             int currrentRotation = anim.GetRotate();
             int newRotation      = currrentRotation == 0 ? (int)Mathf.Sign((int)Random.Range(-1, 1)) : 0;
             anim.SetRotate(newRotation);
             randomRotationTimestamp = Time.realtimeSinceStartup;
         }
     }
     speed            = horizontalInput * maxSpeed;
     walkingDirection = ToDirection(speed);
     anim.SetRotate((int)walkingDirection);
     randomRotationTimestamp = Time.realtimeSinceStartup;
     rigidbody.MovePosition(transform.position + speed * Vector3.right * Time.deltaTime);
     // if speed != 0, walking animation is triggered
     anim.SetSpeed(Mathf.Abs(speed));
     // alternative (not recommended) way of accessing hash IDs directly:
     // animator.SetFloat (anim.paramIdSpeed, Mathf.Abs (speed));
 }