Beispiel #1
0
 public void AttachObject(FirstPersonInteractable interactable)
 {
     attachedInteractableParent    = interactable.transform.parent;
     interactable.transform.parent = objectAttachPoint;
     if (interactable.attachmentPoint)
     {
         interactable.transform.localEulerAngles = -interactable.attachmentPoint.localEulerAngles;
         interactable.transform.position        += objectAttachPoint.transform.position - interactable.attachmentPoint.position;
     }
     else
     {
         interactable.transform.localPosition = Vector3.zero;
     }
     interactable.enabled = false;
     attachedInteractable = interactable;
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (attachedInteractable != null)
        {
            if (Input.GetKeyUp(KeyCode.E))
            {
                DetachObject();
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                throwForce = baseThrowForce;
            }

            if (Input.GetKey(KeyCode.G))
            {
                throwForce += Time.deltaTime * throwForceCharger;
            }

            if (Input.GetKeyUp(KeyCode.G))
            {
                ThrowObject();
            }
        }
        else
        {
            //if (Input.GetKeyDown(KeyCode.E))
            //{
            //    GameObject obj = Instantiate(lr) as GameObject;
            //    LineRenderer line = lr.GetComponent<LineRenderer>();
            //    line.SetPosition(0, transform.position);
            //    line.SetPosition(1, transform.position + transform.forward * 10f);
            //    StartCoroutine(DestroyObject(obj));
            //}



            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 10f, interactableLayer))
            {
                //Debug.Log(hit.collider.gameObject);
                currentInteractable = hit.transform.GetComponent <FirstPersonInteractable>();
                //Debug.Log(currentInteractable);
                if (previousInteractable != currentInteractable)
                {
                    currentInteractable.HoverIn();
                    if (previousInteractable != null)
                    {
                        previousInteractable.HoverOut();
                    }
                }
                else
                {
                    currentInteractable.Hover();
                }

                if (Input.GetKeyDown(KeyCode.E))
                {
                    //lr.enabled = true;
                    if (pressedInteractable != null)
                    {
                        pressedInteractable = null;
                    }
                    else
                    {
                        currentInteractable.PressDown();
                        pressedInteractable = currentInteractable;
                    }
                }

                if (Input.GetKey(KeyCode.E))
                {
                    if (currentInteractable == pressedInteractable)
                    {
                        currentInteractable.Press();
                    }
                }

                if (Input.GetKeyUp(KeyCode.E))
                {
                    //lr.enabled = false;
                    if (currentInteractable == pressedInteractable)
                    {
                        currentInteractable.PressUp();
                    }
                    pressedInteractable = null;
                }
            }
            else
            {
                if (previousInteractable != null)
                {
                    previousInteractable.HoverOut();
                }
                currentInteractable = null;
            }

            previousInteractable = currentInteractable;
        }
    }