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

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, maxDistanceRaycast))
        {
            Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
            //Debug.Log("Did Hit");

            if (hit.collider.gameObject.CompareTag("Interactable"))
            {
                fKey.SetActive(true);
                if (Input.GetKeyDown(KeyCode.F))
                {
                    IInteractable i = hit.collider.gameObject.GetComponent <IInteractable>();
                    i.Action(this);
                }
            }
            else
            {
                fKey.SetActive(false);
            }
        }
        else
        {
            Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward) * maxDistanceRaycast, Color.red);
            //Debug.Log("Did not Hit");

            fKey.SetActive(false);
        }
    }
    void Interact()
    {
        Ray        r = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        RaycastHit hit;

        int ignorePlayer = ~LayerMask.GetMask("Player");

        if (Physics.Raycast(r, out hit, range, ignorePlayer))
        {
            IInteractable i = hit.collider.gameObject.GetComponent <IInteractable>();
            if (i != null)
            {
                i.Action();
            }
        }
    }
예제 #3
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            RaycastHit hit;

            if (Physics.Raycast(Cam.transform.position, Cam.forward, out hit) && hit.transform.CompareTag("Interactable") && hit.distance < 5 && !uiMan.isOpen)
            {
                IInteractable i = hit.transform.GetComponent <IInteractable>();
                i.Action(this);
                //Debug.Log("Hit Object - distance: " + hit.distance);
            }

            if (Physics.Raycast(Cam.transform.position, Cam.forward, out hit) && hit.transform.CompareTag("UIobject") && hit.distance < 5)
            {
                canOpenInventory = false;
                InputField.gameObject.SetActive(true);
                GetComponent <PlayerMovement>().Movement = false;
                Cursor.lockState = CursorLockMode.None;
            }
            if (Physics.Raycast(Cam.transform.position, Cam.forward, out hit) && hit.transform.CompareTag("Craft") && hit.distance < 5)
            {
                if (inventory.CanCraftRaft())
                {
                    BathDuck.SetActive(true);
                }
                else
                {
                    BathDuck.SetActive(false);
                }
            }
            if (Physics.Raycast(Cam.transform.position, Cam.forward, out hit) && hit.transform.CompareTag("Duck") && hit.distance < 5)
            {
                SceneManager.LoadScene(1);
            }
        }

        //Debug.DrawRay(Cam.transform.position, Cam.forward);

        if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Return))
        {
            InputField.gameObject.SetActive(false);
            GetComponent <PlayerMovement>().Movement = true;
            Cursor.lockState = CursorLockMode.Locked;
            canOpenInventory = true;
        }
    }
예제 #4
0
    private void Update()
    {
        if (is_within_interactable)
        {
            if (Input.GetKeyDown(KeyCode.E) &&
                can_move &&
                current_interactable != null)
            {
                current_interactable.Action();
            }
        }

        if (can_move == false && animator.GetBool("Is Player Idle") == false)
        {
            animator.SetBool("Is Player Idle", true);
        }
    }
예제 #5
0
    private void Update()
    {
        PlayerControl();
        CameraControl();
        ObjectDetection();

        if (Input.GetButtonDown("Jump"))
        {
            Ray jumpRay = new Ray(m_ThisTransform.position, -m_ThisTransform.up);
            if (Physics.Raycast(jumpRay, (m_PlayerHeight / 2f) + 0.1f))
            {
                m_ThisRigidbody.AddForce(transform.up * m_JumpForce);
            }
        }

        if (Input.GetButtonDown("Interact"))
        {
            if (p_ActionState != ActionState.Unoccupied)
            {
                IInteractable interactComponent = m_RaycastHit.collider.transform.GetComponent <IInteractable>();

                if (interactComponent != null)
                {
                    interactComponent.Interact(this);
                }
            }
        }

        if (Input.GetButtonDown("Action"))
        {
            if (p_ActionState == ActionState.Holding)
            {
                IInteractable interactComponent = m_RaycastHit.collider.transform.GetComponent <IInteractable>();

                if (interactComponent != null)
                {
                    interactComponent.Action(this);
                }
            }
        }
    }
예제 #6
0
    void Update()
    {
        if (Input.GetButtonDown("Interact"))
        {
            RaycastHit hit;

            if (Physics.SphereCast(transform.position, 0.2f, directionSetter.forward, out hit, 2))
            {
                IInteractable i = hit.collider.gameObject.GetComponent <IInteractable>();
                if (i != null)
                {
                    i.Action(this);
                }
            }
        }

        //Temporary code to test dropping
        if (Input.GetKeyDown(KeyCode.F))
        {
            DropItem("Key of Doom");
        }
    }
예제 #7
0
    private void Interact()
    {
        //ray
        //ray hit check
        //get interactable
        //if != null Action;
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, _range))
        {
            IInteractable i = hit.transform.gameObject.GetComponent <IInteractable>();
            if (i != null)
            {
                i.Action();
            }
            else
            {
                escapeRaft e = hit.transform.gameObject.GetComponent <escapeRaft>();

                e.UpdateRaftStatus();
            }
        }
    }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
        //Interact
        RaycastHit hit;

        interactTxt.text = " ";

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 4f))
        {
            IInteractable i = hit.collider.GetComponent <IInteractable>();

            if (hit.collider.gameObject.tag == "Interactable")
            {
                //Debug.Log("Hit Interactable: " + hit.collider.name);

                if (hit.collider.GetComponent <Pickup>())
                {
                    interactTxt.SetText("Press E to Pick up " + hit.collider.GetComponent <Pickup>().name);
                }
                else if (hit.collider.GetComponent <Door>())
                {
                    interactTxt.SetText("Press E to Open with Key: [" + hit.collider.GetComponent <Door>().id + "]");
                }
                else if (hit.collider.GetComponent <InteractBlank>())
                {
                    interactTxt.SetText("Press E to Interact with: " + hit.collider.gameObject.name);
                }

                if (Input.GetKeyDown(KeyCode.E))
                {
                    i.Action(this);
                }
            }

            /*else if (hit.collider.gameObject.tag != "Interactable")
             * {
             *  interactTxt.text = " ";
             * }*/
        }

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            invOpen = !invOpen; //Switches between True and False to Open and Close the Inventory
        }
        //Sets Inventory into the Active state
        if (invOpen == true)
        {
            Time.timeScale   = 0;
            Cursor.lockState = CursorLockMode.None;
            invUIManager.InvToggle(true);
        }
        else
        { //Sends Inventory into Inactive State
            Time.timeScale   = 1;
            Cursor.lockState = CursorLockMode.Locked;
            invUIManager.InvToggle(false);
        }

        if (inv.HasItem(inv.GetItemWithName("Login")))
        {
            loginNote.SetActive(true);
        }
        else
        {
            loginNote.SetActive(false);
        }
    }
예제 #9
0
    private void Update()
    {
        Debug.DrawRay(playerCam.transform.position, playerCam.transform.forward * 4, Color.red);
        if (Input.GetKeyDown(KeyCode.E))
        {
            RaycastHit hit;

            if (Physics.SphereCast(playerCam.transform.position, 0.5f, playerCam.transform.forward, out hit, 4))
            {
                //Debug.Log("Hit something");
                IInteractable i = hit.collider.gameObject.GetComponent <IInteractable>();
                if (i != null)
                {
                    Debug.Log("Hit an interactable.");
                    i.Action(this);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            if (itemName == null)
            {
                DropItem(inventory.GetLastItem().GetName());
            }
            else
            {
                DropItem(itemName);
                itemName = null;
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            if (canAPI)
            {
                if (Cursor.lockState == CursorLockMode.Locked)
                {
                    inpUI.SetActive(true);
                    invUI.GetComponent <Canvas>().enabled = false;
                    EnableUI();
                }
                else if (Cursor.lockState == CursorLockMode.None)
                {
                    inpUI.SetActive(false);
                    DisableUI();
                }
            }
            else
            {
                inpUI.SetActive(false);
                if (Cursor.lockState == CursorLockMode.Locked)
                {
                    invUI.GetComponent <Canvas>().enabled = true;
                    EnableUI();
                }
                else if (Cursor.lockState == CursorLockMode.None)
                {
                    invUI.GetComponent <Canvas>().enabled = false;
                    DisableUI();
                }
            }
        }

        if (Input.GetKey(KeyCode.W) && canClimb)
        {
            rb.AddForce(0, upSpeed, 0);
        }
    }
    // Update is called once per frame
    void Update()
    {
        crossHair.SetActive(false);

        // Shoots a raycast that shows a crosshair on interactable hit
        if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
        {
            IInteractable i = hit.collider.gameObject.GetComponent <IInteractable>();
            if (i != null)
            {
                crossHair.SetActive(true);

                // press interact to interact with the object
                if (Input.GetButtonDown("Interact"))
                {
                    i.Action(this);
                }
            }
        }

        // Drop the item in the selected slot
        if (Input.GetButtonDown("Drop"))
        {
            DropItem(GameManager.Instance.selectedSlotIndex);
        }

        // For switching selected inventory slots
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            GameManager.Instance.selectedSlotIndex = 0;
            GameManager.Instance.CheckSlotId();
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            GameManager.Instance.selectedSlotIndex = 1;
            GameManager.Instance.CheckSlotId();
        }

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            GameManager.Instance.selectedSlotIndex = 2;
            GameManager.Instance.CheckSlotId();
        }

        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            GameManager.Instance.selectedSlotIndex = 3;
            GameManager.Instance.CheckSlotId();
        }

        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            GameManager.Instance.selectedSlotIndex = 4;
            GameManager.Instance.CheckSlotId();
        }

        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            GameManager.Instance.selectedSlotIndex = 5;
            GameManager.Instance.CheckSlotId();
        }
    }