Ejemplo n.º 1
0
        private void Pull()
        {
            Joint.enabled = true;

            var otherRigidbody = GrabbedObj ? GrabbedObj.GetComponent <Rigidbody2D>() : null;

            Joint.connectedBody = otherRigidbody;

            if (otherRigidbody && !otherRigidbody.bodyType.Equals(RigidbodyType2D.Static))
            {
                // if player is facing a direction other than that of the otherRigidbody, Flip()
                var otherIsToTheRight = otherRigidbody.gameObject.transform.position.x > transform.position.x;
                if (otherIsToTheRight ^ PlayerMove.FacingRight)
                {
                    PlayerMove.Flip();
                }

                CloseDistance();
                RenderLine();
            }
            else if (!otherRigidbody)
            {
                Debug.LogError("Connected body is null!");
                EndGrapple();
            }
        }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        hits = Physics.RaycastAll(transform.parent.position, transform.parent.forward, HandLength);
        if (hits.Length != 0)
        {
            OperObj = hits[hits.Length - 1].transform;
            //Debug.Log(OperObj.name);
        }
        else
        {
            OperObj = null;
        }
        if (!grabbed)
        {
            if (OperObj != null && OperObj.GetComponent <Act>() != null)
            {
                captured      = true;
                GrabbedObjAct = OperObj.GetComponent <Act>();

                if (Input.GetMouseButtonDown(GrabButton) && GrabbedObjAct.Grabable)
                {
                    GrabbedObjAct.Grab();
                    grabbed    = true;
                    GrabbedObj = OperObj;

                    GrabbedObj.gameObject.layer = 8;
                    for (int i = 0; i < GrabbedObj.childCount; i++)
                    {
                        GrabbedObj.GetChild(i).gameObject.layer = GrabbedObj.gameObject.layer;
                    }
                }
                else if (Input.GetMouseButtonDown(OperationButton))
                {
                    GrabbedObjAct.Operate();
                }
            }
            else
            {
                captured = false;
            }
        }
        else
        {
            if (OperObj != null && (OperObj.GetComponent <BaseToPut>() != null && OperObj.GetComponent <BaseToPut>().PutableObject == GrabbedObj || OperObj.parent != null && OperObj.parent.GetComponent <BaseToPut>() != null && OperObj.parent.GetComponent <BaseToPut>().PutableObject == GrabbedObj))
            {
                captured = true;
                if (Input.GetMouseButtonDown(OperationButton))
                {
                    if (OperObj.GetComponent <BaseToPut>() != null)
                    {
                        GrabbedObj.GetComponent <Act>().Put(OperObj);
                    }
                    else
                    {
                        GrabbedObj.GetComponent <Act>().Put(OperObj.parent);
                    }

                    GrabbedObj.gameObject.layer = 0;
                    for (int i = 0; i < GrabbedObj.childCount; i++)
                    {
                        GrabbedObj.GetChild(i).gameObject.layer = GrabbedObj.gameObject.layer;
                    }

                    grabbed  = false;
                    captured = false;
                }
            }
            else
            {
                captured = false;

                if (Input.GetMouseButtonDown(DropButton))
                {
                    GrabbedObjAct.Drop(gameObject.GetComponent <Rigidbody>().velocity, gameObject.GetComponent <Rigidbody>().angularVelocity);
                    GrabbedObj.gameObject.layer = 0;
                    for (int i = 0; i < GrabbedObj.childCount; i++)
                    {
                        GrabbedObj.GetChild(i).gameObject.layer = GrabbedObj.gameObject.layer;
                    }

                    grabbed = false;
                }
                else if (Input.GetMouseButtonDown(OperationButton))
                {
                    GrabbedObjAct.Operate();
                }
            }
        }
    }