Exemple #1
0
    /// <summary>
    /// Connects two objects
    /// </summary>
    /// <param name="obj"></param>
    /// <param name="start"></param>
    /// <param name="end"></param>

    void Update()
    {
        if (Input.GetButtonDown("Create_Grappling_Hook") && !pMov.getMovementDisabled())
        {
            if (!grappling)
            {
                Vector3 newVec = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f));
                newVec *= -1;
                newVec.Normalize();
                if (Physics2D.Raycast(transform.position, newVec, range, possibleLayers))
                {
                    targetCast = Physics2D.Raycast(transform.position, newVec, range, possibleLayers);
                    oldTarget  = targetCast.point;
                    hasHitObj  = true;
                    pMov.setGrappling(true);
                }
                else
                {
                    hasHitObj = false;
                    oldTarget = transform.position + (newVec * range);
                }
                target = oldTarget;
                Debug.DrawLine(transform.position, (target), Color.green, 1.0f, true);
                grapple();
            }
        }
        if (Input.GetButtonDown("Release_Grappling_Hook"))
        {
            pMov.setGrappling(false);
            removeLine();
            grappling = false;
        }
        if (grappling)
        {
            if (!hasHitObj)
            {
                Vector3 newVec = transform.position - end.transform.position;
                newVec *= -1;
                newVec.Normalize();
                if (Physics2D.Raycast(transform.position, newVec, range, possibleLayers))
                {
                    //if it hits an object
                    targetCast = Physics2D.Raycast(transform.position, newVec, range, possibleLayers);
                    oldTarget  = targetCast.point;
                    hasHitObj  = true;
                    target     = oldTarget;
                    grapple();
                }
            }
        }
        if (Input.GetAxis("Change_Grappling_Hook_Length") != 0 && grappling)
        {
            if (checkLimits())
            {
                Debug.DrawLine(transform.position, end.transform.position, Color.red, 5f, false);
                if (hasHitObj)
                {
                    if (Input.GetAxis("Change_Grappling_Hook_Length") > 0)
                    {
                        if (Vector3.Magnitude(player.transform.position - end.transform.position) > minimumDistance)
                        {
                            changeLength(true);
                        }
                    }
                    else
                    {
                        if (Vector3.Magnitude(player.transform.position - end.transform.position) < range)
                        {
                            changeLength(false);
                        }
                    }
                }
                else
                {
                    if (Input.GetAxis("Change_Grappling_Hook_Length") > 0)
                    {
                        if (Vector3.Magnitude(player.transform.position - end.transform.position) > minimumDistance)
                        {
                            //   changeLengthWithoutPlayerMovement(true);
                        }
                    }
                    else
                    {
                        if (Vector3.Magnitude(player.transform.position - end.transform.position) < range)
                        {
                            //  changeLengthWithoutPlayerMovement(false);
                        }
                    }
                }
            }
        }
    }
Exemple #2
0
 public void Update()
 {
     if (!trackingPlayer)
     {
         if (!reverting)
         {
             if (Mathf.Abs((graves [graves.Count - 1]).GetComponent <Rigidbody2D> ().velocity.x + graves [graves.Count - 1].GetComponent <Rigidbody2D> ().velocity.y) <= minimumSpeed)
             {
                 Invoke("revertTarget", minimumDelay);
                 reverting = true;
             }
             if (Input.anyKeyDown)
             {
                 revertTarget();
             }
         }
         else
         {
             if (Mathf.Abs((graves [graves.Count - 1]).GetComponent <Rigidbody2D> ().velocity.x + graves [graves.Count - 1].GetComponent <Rigidbody2D> ().velocity.y) >= minimumSpeed)
             {
                 reverting = false;
                 CancelInvoke();
                 Invoke("revertTarget", maximumDelay);
             }
         }
     }
     else
     {
         if (Input.GetButtonDown(pillSpawn))
         {
             if (pillsList.getLivesLeft() > 0)
             {
                 GameObject g = createBlock(Block, BlockSilhouette, blockYOffset);
                 if (g != null)
                 {
                     blocks.Add(g);
                     pillsList.suicide();
                 }
                 else
                 {
                     pillsList.flash();
                 }
             }
             else
             {
                 pillsList.flash();
             }
         }
         if (Input.GetButtonDown(heartSpawn) && !p.getMovementDisabled())
         {
             if (heartsList.getLivesLeft() > 0)
             {
                 GameObject g = createBlock(Gravestone, GravestoneSilhouette, gravesYOffset);
                 if (g != null)
                 {
                     graves.Add(g);
                     camTrack.setTarget((graves [graves.Count - 1]).transform);
                     Invoke("revertTarget", maximumDelay);
                     trackingPlayer = false;
                     p.setMovementDisabled(true);
                     p.renderer.enabled = false;
                     foreach (Transform child in transform)
                     {
                         try {
                             child.renderer.enabled = false;
                         } catch {
                         }
                     }
                     collider2D.enabled = false;
                 }
                 else
                 {
                     heartsList.flash();
                 }
             }
             else
             {
                 heartsList.flash();
             }
         }
     }
 }