Exemplo n.º 1
0
 private void Update()
 {
     if (GameInput.GetKeyDown(player, ActionKey))
     {
         MovementAction movement = GetComponent <MovementAction>();
         Selecting = true;
         if (movement != null)
         {
             movement.enabled = false;
         }
         ((CombineSelection)selection).StartSelecting(this, player, "Combinable", Range);
     }
     if (GameInput.GetKeyUp(player, ActionKey))
     {
         Selecting = false;
         GameObject g = selection.StopSelecting();
         if (g != null)
         {
             if (Upper != null && g == Upper.gameObject)
             {
                 UpperJoint.connectedBody = null;
                 UpperJoint.enabled       = false;
                 Upper.Separated(true);
                 Upper = null;
             }
             else if (Lower != null && g == Lower.gameObject)
             {
                 LowerJoint.connectedBody = null;
                 LowerJoint.enabled       = false;
                 Lower.Separated(false);
                 Lower = null;
             }
             else
             {
                 CombineAction comb = g.GetComponent <CombineAction>();
                 if (comb.part > part)
                 {
                     comb.transform.position  = comb.transform.position + (UpperAttachPoint.position - comb.LowerAttachPoint.position);
                     UpperJoint.enabled       = true;
                     UpperJoint.connectedBody = comb.GetComponent <Rigidbody2D>();
                     Upper = comb;
                     comb.Combined(true, this);
                     if (comb.GetMass() > SupportableMass)
                     {
                         Break();
                     }
                 }
                 else
                 {
                     transform.position       = transform.position + (comb.UpperAttachPoint.position - LowerAttachPoint.position);
                     LowerJoint.enabled       = true;
                     LowerJoint.connectedBody = comb.GetComponent <Rigidbody2D>();
                     Lower = comb;
                     comb.Combined(false, this);
                 }
             }
             UpdateMovement();
         }
         if (Movement)
         {
             MovementAction movement = GetComponent <MovementAction>();
             if (movement != null)
             {
                 movement.enabled = true;
             }
         }
     }
 }