예제 #1
0
    private void FixedUpdate()
    {
        RaycastHit hit;

        Debug.DrawRay(transform.position + 1.8f * Vector3.up, transform.TransformDirection(Vector3.forward), Color.green);

        int layerMask = 1 << 9;

        if (Physics.Raycast(transform.position + 1.8f * Vector3.up, transform.TransformDirection(Vector3.forward), out hit, 1f, layerMask))
        {
            hasInteractable = true;

            if (Input.GetKeyDown(KeyCode.E))
            {
                IInteractable target = hit.collider.gameObject.GetComponent <IInteractable>();
                target.Activate();
            }
        }
        else
        {
            hasInteractable = false;
        }

        interactText.gameObject.SetActive(hasInteractable);
    }
예제 #2
0
    IEnumerator WaitForInput()
    {
        while (!Input.GetButtonDown(inputName) || Time.timeScale == 0)
        {
            yield return(null);
        }

        interactableObject.Activate();
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UIManager.Instance.setPauseVisible(true);
        }

        if (Input.GetKeyDown(KeyCode.E) && targetInteractable != null)
        {
            targetInteractable.Activate();
        }
    }
예제 #4
0
    void pickUp(leftRight lr)
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
        {
            MonoBehaviour[] scripts = hit.collider.gameObject.GetComponents <MonoBehaviour>();
            if (scripts.Length > 0)
            {
                foreach (MonoBehaviour script in scripts)
                {
                    if (script is IPickable)
                    {
                        if (lr == leftRight.left)
                        {
                            if (leftHand != null)
                            {
                                DropObject(leftRight.left);
                            }
                            leftHand = placeObject(leftRight.left, hit.collider.gameObject);
                        }
                        else
                        {
                            if (rightHand != null)
                            {
                                DropObject(leftRight.right);
                            }
                            rightHand = placeObject(leftRight.right, hit.collider.gameObject);
                        }
                        return;
                    }

                    if (script is IInteractable)
                    {
                        IInteractable localScript = (IInteractable)script;
                        localScript.Activate();
                    }



                    //if(specialcaseScript)
                    //Execute special case
                }
            }

            DropObject(lr);
        }
        else
        {
            DropObject(lr);
        }
    }
예제 #5
0
 // Update is called once per frame
 void Update()
 {
     if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.W)))
     {
         isRunning = true;
     }
     else
     {
         isRunning = false;
     }
     if (interactObject != null && Input.GetKeyDown(KeyCode.E))
     {
         interactObject.Activate(this);
     }
 }