Пример #1
0
 public bool AddPart(string partName)
 {
     for (int i = 0; i < parts.Length; i++)
     {
         if (partName == slotNames[i] && !parts[i])
         {
             parts[i] = (GameObject)Instantiate(invMng.GetPart(partName), partPositions[i], partRotations[i]);
             parts[i].transform.localScale = partScales[i];
             parts[i].transform.SetParent(transform);
             invMng.RefreshInventory();
             return(true);
         }
     }
     return(false);
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        blockRayThisFrame = false;

        if (!isOnComputer)
        {
            var objs = GameObject.FindGameObjectsWithTag("ComputerButton");
            foreach (GameObject gb in objs)
            {
                gb.GetComponent <Button>().interactable = false;
            }
        }
        else
        {
            var objs = GameObject.FindGameObjectsWithTag("ComputerButton");
            foreach (GameObject gb in objs)
            {
                gb.GetComponent <Button>().interactable = true;
            }
        }


        if (Input.GetMouseButton(0) && canMove && Cursor.lockState != CursorLockMode.Locked)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;
        }

        if (Input.GetKeyDown(KeyCode.C) && Cursor.lockState == CursorLockMode.Locked)
        {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = true;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            if (isOnComputer && !canMove)
            {
                blockRayThisFrame = true;

                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;
                plyCam.enabled   = true;
                isOnComputer     = false;

                computerCamera.enabled = false;
                canMove = true;
            }
            else if (isRepairingTV && !canMove)
            {
                blockRayThisFrame = true;

                isRepairingTV     = false;
                plyCam.enabled    = true;
                lastTVCam.enabled = false;
                lastTVCam.GetComponent <PhysicsRaycaster>().enabled = false;

                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;
                canMove          = true;
            }
        }


        if (lastObj != null)
        {
            hudCanvas.SetActive(false);

            lastObj.GetComponent <InteractableObject>().isLookingAt = false;
            //hudCanvas.GetComponentInChildren<Image>().sprite = null;
            //hudCanvas.GetComponentInChildren<Text>().text = "";
            //var img = hudCanvas.GetComponentInChildren<Image>();
        }

        RaycastHit hit;
        Ray        objRay = new Ray(plyCam.transform.position, plyCam.transform.forward);

        if (Physics.Raycast(objRay, out hit, InteractionDistance) && !blockRayThisFrame)
        {
            if (hit.collider.tag == "Interactable")
            {
                lastObj = hit.collider.gameObject;
                var script = hit.collider.GetComponent <InteractableObject>();


                if (!isOnComputer)
                {
                    script.isLookingAt = true;
                    if (script.DisplaySprite)
                    {
                        hudCanvas.SetActive(true);
                        var img = hudCanvas.GetComponentInChildren <Image>();
                        img.sprite = script.DisplaySprite;
                        img.color  = hudImageColor;
                        hudCanvas.GetComponentInChildren <Text>().text = script.DisplayText;
                    }
                }

                if (Input.GetKeyDown(KeyCode.E))
                {
                    switch (script.DisplayText)
                    {
                    case "Computer":
                        if (canMove)
                        {
                            Cursor.lockState = CursorLockMode.None;
                            Cursor.visible   = true;

                            computerCamera.enabled = true;
                            isOnComputer           = true;
                            plyCam.enabled         = false;
                            canMove            = false;
                            script.isLookingAt = false;
                        }
                        break;
                    }
                }
            }
            else if (hit.collider.tag == "TV")
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    Cursor.lockState = CursorLockMode.None;
                    Cursor.visible   = true;
                    currentTV        = hit.collider.transform.parent.gameObject;
                    var script = hit.collider.GetComponentInParent <InteractableTV>();
                    canMove   = false;
                    lastTVCam = script.gameObject.GetComponentInChildren <Camera>();
                    lastTVCam.GetComponent <PhysicsRaycaster>().enabled = true;
                    lastTVCam.enabled = true;
                    plyCam.enabled    = false;
                    isRepairingTV     = true;

                    invMng.RefreshInventory();
                }
            }
        }
        else
        {
            if (lastObj != null)
            {
                lastObj.GetComponent <InteractableObject>().isLookingAt = false;
                lastObj = null;
            }
        }
    }