Пример #1
0
    void FixedUpdate()
    {
        Collider[] nearby = Physics.OverlapSphere(transform.position, m_attachTolerance);

        m_attachedHose = null;
        foreach (Collider c in nearby)
        {
            HoseEnd hose = c.GetComponent <HoseEnd>();
            if (hose != null && !hose.m_held && m_attachedHose == null)
            {
                hose.m_connectionJoint.connectedAnchor = transform.position;
                if (hose != null)
                {
                    hose.m_connectionJoint.xMotion = ConfigurableJointMotion.Locked;
                    hose.m_connectionJoint.yMotion = ConfigurableJointMotion.Locked;
                    hose.m_connectionJoint.zMotion = ConfigurableJointMotion.Locked;

                    m_attachedHose = hose;

                    Rigidbody hoseRb = hose.GetComponent <Rigidbody>();
                    if (hoseRb != null)
                    {
                        hoseRb.freezeRotation  = true;
                        hoseRb.angularVelocity = Vector3.zero;
                    }
                }

                break;
            }
        }

        if (m_attachedHose)
        {
            foreach (Collider c in nearby)
            {
                {
                    m_attachedHose.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
                    Packet packet = c.GetComponent <Packet>();
                    if (packet && packet.currentTansmission.source == m_port)
                    {
                        m_attachedHose.Send(packet);
                    }
                }
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (disable)
        {
            return;
        }

        RaycastHit raycastHit;

        if (m_attachedObject == null && (Input.GetButtonDown("Interact") || Input.GetButtonDown("Throw")))
        {
            Vector3 raycastStart = m_viewCamera.transform.position + (m_viewCamera.transform.forward * 0.1f);
            if (Physics.Raycast(raycastStart, m_viewCamera.transform.forward, out raycastHit, m_pickupRange))
            {
                //Debug.Log(raycastHit.transform.name);
                if (raycastHit.transform != transform)
                {
                    //m_carrying = true;
                    var pickupTarget = raycastHit.transform.GetComponentInParent(typeof(PickupTarget)) as PickupTarget;
                    if (pickupTarget)
                    {
                        m_attachedObject = pickupTarget.transform;
                        //m_attachedObject.transform.position = m_viewCamera.transform.position + m_viewCamera.transform.forward;
                        //m_attachedObject.transform.parent = m_viewCamera.transform;
                        Rigidbody rb = m_attachedObject.GetComponent <Rigidbody>();
                        if (rb != null)
                        {
                            pickupTarget.OnPickup();
                            m_attachedObjectOriginalLayer = m_attachedObject.gameObject.layer;
                            //m_attachedObject.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer");
                        }
                        HoseEnd hoseEnd = m_attachedObject.GetComponent <HoseEnd>();
                        if (hoseEnd != null)
                        {
                            hoseEnd.m_held = true;
                            hoseEnd.m_connectionJoint.xMotion = ConfigurableJointMotion.Free;
                            hoseEnd.m_connectionJoint.yMotion = ConfigurableJointMotion.Free;
                            hoseEnd.m_connectionJoint.zMotion = ConfigurableJointMotion.Free;
                        }
                        //                         Rigidbody hoseRb = hoseEnd.GetComponent<Rigidbody>();
                        //                         if (hoseRb != null)
                        //                         {
                        //                             hoseRb.useGravity = true;
                        //                             hoseRb.freezeRotation = false;
                        //                         }
                        //                         if  (hoseEnd  != null)
                        //                         {
                        //                             hoseEnd.m_held = true;
                        //                             if (hoseEnd.m_attachTo != null)
                        //                             {
                        //                                 HoseAttachPoint hoseAttach = hoseEnd.m_attachTo.GetComponent<HoseAttachPoint>();
                        //                                 if (hoseAttach != null)
                        //                                 {
                        //                                     hoseAttach.m_attachedHose = null;
                        //                                 }
                        //
                        //                                 hoseEnd.m_attachTo = null;
                        //                             }
                        //                         }
                    }
                }
            }
        }
        else if (m_attachedObject != null && Input.GetButtonDown("Interact"))
        {
            //m_attachedObject.transform.parent = null;
            m_attachedObject.gameObject.layer = m_attachedObjectOriginalLayer;
            m_attachedObjectOriginalLayer     = -1;
            Rigidbody rb = m_attachedObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                var pickupTarget = m_attachedObject.GetComponent <PickupTarget>();
                pickupTarget.OnDrop();
            }
            HoseEnd hoseEnd = m_attachedObject.GetComponent <HoseEnd>();
            if (hoseEnd != null)
            {
                hoseEnd.m_held = false;
            }
            m_attachedObject = null;
            //m_carrying = false;
        }

        else if (m_attachedObject != null && Input.GetButtonDown("Throw"))
        {
            //m_attachedObject.transform.parent = null;
            var bucket = m_attachedObject.GetComponent <Bucket>();
            if (!bucket)
            {
                m_attachedObject.gameObject.layer = m_attachedObjectOriginalLayer;
                m_attachedObjectOriginalLayer     = -1;
            }

            Rigidbody rb = m_attachedObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                var pickupTarget = m_attachedObject.GetComponent <PickupTarget>();
                pickupTarget.OnThrow();
            }
            HoseEnd hoseEnd = m_attachedObject.GetComponent <HoseEnd>();
            if (hoseEnd != null)
            {
                hoseEnd.m_held = false;
            }

            if (!bucket)
            {
                m_attachedObject = null;
            }

            rb.AddForceAtPosition(m_viewCamera.transform.forward * m_throwForce, m_attachmentPoint.position);
        }
    }