Exemple #1
0
    private void Update()
    {
        justGrabbed = false;
        invertSymbol.SetActive(false);
        grabTip.SetActive(false);
        releaseTip.SetActive(false);

        RaycastHit hitInfo;

        if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, 10000, layer))
        {
            invertable = hitInfo.transform.gameObject.GetComponent <Invertable>();
            grabable   = hitInfo.transform.gameObject.GetComponent <Grabable>();
            if (invertable != null)
            {
                if (!playerInput.CoursorFree)
                {
                    invertSymbol.SetActive(true);
                }
                if (Input.GetKeyDown(KeyCode.Mouse0) && !playerInput.CoursorFree)
                {
                    InvertorSlot slot = InvertionManager.Instance.GetFreeInvertorSlot();
                    if (slot != null)
                    {
                        Invertor invertor = new Invertor();
                        slot.TakeSlot(invertor, invertor.Apply(invertable));
                    }
                }
            }

            if (grabable != null && currentGrabable == null)
            {
                grabTip.SetActive(true);
                if (Input.GetKeyDown(KeyCode.F) && !playerInput.CoursorFree)
                {
                    grabable.Grab(grabTransform, 2);
                    currentGrabable = grabable;
                    justGrabbed     = true;
                }
            }
        }

        if (currentGrabable != null)
        {
            releaseTip.SetActive(true);
        }


        if (!justGrabbed && Input.GetKeyDown(KeyCode.F) && currentGrabable != null)
        {
            currentGrabable.Release();
            currentGrabable = null;
        }

        if (currentGrabable != null && currentGrabable.Target != grabTransform)
        {
            currentGrabable = null;
        }
    }
Exemple #2
0
 void Grab(Grabable grabbed)
 {
     if (this.grabbed == null && grabbed.transform.parent == null)
     {
         this.grabbed               = grabbed;
         constructor.Mass          += grabbed.Mass;
         grabbed.transform.parent   = grabTransform;
         grabbed.transform.position = grabTransform.position;
         grabbed.Grab();
     }
 }
Exemple #3
0
    public void OnTriggerEnter(Collider other)
    {
        if (grabableObject == null)
        {
            Grabable grabable = other.gameObject.GetComponent <Grabable>();

            if (grabable != null)
            {
                grabableObject = grabable;
                grabable.Grab(gameObject);
            }
        }
    }
    private void Update()
    {
        HandleMovement();

        m_PointedItem?.Highlight(false);
        m_PointedItem = null;

        Ray        ray = new Ray(m_CameraTransform.position, m_CameraTransform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, m_GrabDistance, m_GrabableMask))
        {
            m_PointedItem = hit.collider.GetComponentInParent <Grabable>();
            if (m_PointedItem)
            {
                m_PointedItem.Highlight(true);
            }
        }

        if (Input.GetMouseButtonDown(0) && m_GrabbedItem)
        {
            var gun = m_GrabbedItem.GetComponent <Gun>();
            if (gun)
            {
                gun.Fire();
            }
        }

        if (Input.GetMouseButtonDown(0) && m_PointedItem)
        {
            m_GrabbedItem = m_PointedItem;
            m_GrabbedItem.Highlight(false);
            m_GrabbedItem.Grab(m_GrabHook);
        }

        if (Input.GetMouseButtonDown(1) && m_GrabbedItem)
        {
            m_GrabbedItem.Release();
            m_GrabbedItem = null;
        }

        if (Input.GetKeyDown(KeyCode.E) && hit.collider)
        {
            //Debug.Log(hit.collider.gameObject.name);
            var button = hit.collider.GetComponentInParent <BigButton>();
            if (button)
            {
                button.Push();
            }
        }
    }
Exemple #5
0
 private void SetOpen(bool check, Grabable grabable = null)
 {
     if (!reversMode)
     {
         if (check)
         {
             lockObject.SetActive(false);
             lockGlow.material       = greenMat;
             lineRenderer.startColor = Color.green;
             lineRenderer.endColor   = Color.green;
             text.text = "";
             if (grabable != null)
             {
                 grabable.Grab(transform, 0);
             }
         }
         else
         {
             lockObject.SetActive(true);
             lockGlow.material       = redMat;
             lineRenderer.startColor = Color.red;
             lineRenderer.endColor   = Color.red;
             text.text = textRequirement;
         }
     }
     else
     {
         if (check)
         {
             lockGlow.material       = greenMat;
             lineRenderer.startColor = Color.green;
             lineRenderer.endColor   = Color.green;
             text.text = "";
         }
         else
         {
             lockGlow.material       = redMat;
             lineRenderer.startColor = Color.red;
             lineRenderer.endColor   = Color.red;
             if (openWhenHaveObject)
             {
                 text.text = "OBJECT\nMISSING";
             }
             else
             {
                 text.text = "REMOVE\nOBJECT";
             }
         }
     }
 }
Exemple #6
0
    public Grabable Swap(Grabable grabable)
    {
        Grabable grab = grabableObject;

        grabableObject = grabable;

        if (grabable != null)
        {
            grabable.Grab(gameObject);
        }

        if (grab != null)
        {
            grab.Drop();
        }

        return(grab);
    }