コード例 #1
0
 /// <summary>
 /// Unity update hook.
 /// </summary>
 void Update()
 {
     BoxOnTop = false;
     velocity = new Vector2(0.0f, velocity.y);
     if (controller != null)
     {
         // If the controller is doing something other than walking/running/pushing/etc then UnLatch it
         if (controller.State != CharacterState.IDLE && controller.State != CharacterState.WALKING && controller.State != CharacterState.RUNNING &&
             controller.State != CharacterState.PUSHING && controller.State != CharacterState.PULLING)
         {
             UnLatch();
         }
         // If you pull a box then release then unlatch.
         else if (hasPulled && controller.characterInput.x == 0)
         {
             UnLatch();
         }
         // If character is not grounded then unlatch.
         else if (controller.GroundedFeetCount <= 1)
         {
             UnLatch();
         }
         // If character is moving too fast then unlatch.
         else if (velocity.y > minVelocityForUnLatch || velocity.y < (minVelocityForUnLatch * -1))
         {
             UnLatch();
         }
         else
         {
             // TODO Why am I checking this twice?!?
             if (controller != null)
             {
                 velocity = new Vector2(controller.Velocity.x, 0.0f);
                 // Animation
                 if (direction == RC_Direction.RIGHT && controller.characterInput.x > 0)
                 {
                     controller.ForceSetCharacterState(CharacterState.PUSHING);
                 }
                 else if (direction == RC_Direction.RIGHT && controller.characterInput.x < 0)
                 {
                     controller.ForceSetCharacterState(CharacterState.PULLING);
                     hasPulled = true;
                 }
                 else if (direction == RC_Direction.LEFT && controller.characterInput.x < 0)
                 {
                     controller.ForceSetCharacterState(CharacterState.PUSHING);
                 }
                 else if (direction == RC_Direction.LEFT && controller.characterInput.x > 0)
                 {
                     controller.ForceSetCharacterState(CharacterState.PULLING);
                     hasPulled = true;
                 }
             }
         }
     }
 }