Пример #1
0
 void Update()
 {
     if (kc.isUnderPlayerControl())
     {
         var movement = Input.GetAxisRaw("Horizontal");
         if (movement > 0)
         {
             kc.Move(1);
         }
         else if (movement < 0)
         {
             kc.Move(-1);
         }
         else
         {
             kc.Move(0);
         }
     }
 }
Пример #2
0
    private void Synchronize()
    {
        var snapped = TrySnapPosition();

        Debug.Log(snapped);

        if (!snapped)
        {
            // flip toward goal
            float xDiff = transform.position.x - playerTransform.position.x;
            if (xDiff > 0 && attachedPlayer.direction == Direction.Left)
            {
                Debug.Log("Flipping");
                attachedPlayer.ChangeDirection(Direction.Right);
            }
            else if (xDiff < 0 && attachedPlayer.direction == Direction.Right)
            {
                Debug.Log("Flipping");
                attachedPlayer.ChangeDirection(Direction.Left);
            }
            else
            {
                // move to goal position
                Debug.Log("Moving to goal");
                attachedPlayer.Move(xDiff);
            }
        }
        else
        {
            // flip to goal direction
            if (attachedPlayer.direction != goalDirection)
            {
                Debug.Log("Aligning to goal");
                attachedPlayer.ChangeDirection(goalDirection);
            }
        }
    }