Example #1
0
 void Start()
 {
     highlightColor = Color.green;
     l = GameObject.Find("Light");
     Test   light = GetComponent <Test>();
     UI_Key trash = GetComponent <UI_Key>();
 }
Example #2
0
    void Update()
    {
        RaycastHit hitInfo;
        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
        Renderer   currRenderer;

        #region Highlight Object
        if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, distanceToSee))
        {
            #region InteractionScript
            if (Input.GetKeyDown(KeyCode.E))
            {
                //Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                RaycastHit hit;

                if (Physics.Raycast(ray.origin, ray.direction, out hit, interactionRadius))
                {
                    DoorInteraction doorObject = hit.collider.GetComponent <DoorInteraction>();
                    if (doorObject)
                    {
                        doorObject.Toggle();
                    }

                    FileCabinetScript fileCabinet = hit.collider.GetComponent <FileCabinetScript>();
                    if (fileCabinet)
                    {
                        fileCabinet.ToggleDrawer();
                    }

                    DrawerInteraction drawerObject = hit.collider.GetComponent <DrawerInteraction>();
                    if (drawerObject)
                    {
                        drawerObject.ToggleDrawer();
                    }

                    UI_Key keyObject = hit.collider.GetComponent <UI_Key>();
                    if (keyObject)
                    {
                        keyObject.KeyAdd();
                    }
                }
            }
            #endregion


            if (hitInfo.transform.tag == "collectible" || hitInfo.transform.tag == "key")
            {
                // collect object and delete it from scene, adding +1 to inventory
                if (Input.GetKey(KeyCode.E))
                {
                    if (hitInfo.transform.tag == "key")
                    {
                        trash.KeyAdd();
                        key += 1;
                        Debug.LogFormat("Keys: {0} ", key);
                    }
                    if (hitInfo.transform.tag == "collectible")
                    {
                        collectible += 1;
                        Debug.LogFormat("collectibles: {0} ", collectible);
                    }
                    Destroy(hitInfo.collider.gameObject);
                }
                currRenderer = hitInfo.collider.gameObject.GetComponent <Renderer>();

                if (currRenderer == renderer)
                {
                    return;
                }

                if (currRenderer && currRenderer != renderer)
                {
                    if (renderer)
                    {
                        renderer.sharedMaterial = originalMaterial;
                    }
                }

                if (currRenderer)
                {
                    renderer = currRenderer;
                }
                else
                {
                    return;
                }

                originalMaterial = renderer.sharedMaterial;

                tempMaterial            = new Material(originalMaterial);
                renderer.material       = tempMaterial;
                renderer.material.color = highlightColor;
            }
            else
            {
                if (renderer)
                {
                    renderer.sharedMaterial = originalMaterial;
                    renderer = null;
                }
            }
        }
        #endregion
    }
Example #3
0
    void Update()
    {
        key = GetComponent <UI_Key>();
        if (safeKey == true)
        {
            key.keyCount = 1;
        }
        Debug.Log(key.keyCount);
        Debug.LogFormat("safeKey interaction{0}", safeKey);

        if (Input.GetKeyDown(KeyCode.E))
        {
            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            RaycastHit hit;

            if (Physics.Raycast(ray.origin, ray.direction, out hit, interactionRadius))
            {
                DoorInteraction doorObject = hit.collider.GetComponent <DoorInteraction>();
                if (doorObject)
                {
                    Debug.Log(hit.collider.tag);
                    if (hit.collider.tag == "safe")
                    {
                        if (safeKey == true)
                        {
                            doorObject.Toggle();
                        }
                        else if (safeKey == false)
                        {
                            Debug.Log("no key");
                        }
                    }
                    if (doorObject.tag != "safe")
                    {
                        doorObject.Toggle();
                    }
                }

                // File Cabinet Interaction
                FileCabinetScript fileCabinet = hit.collider.GetComponent <FileCabinetScript>();
                if (fileCabinet)
                {
                    fileCabinet.ToggleDrawer();
                }

                // drawer interaction
                DrawerInteraction drawerObject = hit.collider.GetComponent <DrawerInteraction>();
                if (drawerObject)
                {
                    drawerObject.ToggleDrawer();
                }

                // Keyobject interaction
                UI_Key keyObject = hit.collider.GetComponent <UI_Key>();
                if (keyObject)
                {
                    safeKey = true;
                }

                DrawerInteractionHenry drawerObjectHenry = hit.collider.GetComponent <DrawerInteractionHenry>();
                if (drawerObjectHenry)
                {
                    drawerObjectHenry.ToggleDrawer();
                }
            }
        }
    }
Example #4
0
    void Update()
    {
        //Debug.Log(keyForSafe);
        Debug.Log(key);
        RaycastHit hitInfo;
        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
        Renderer   currRenderer;

        if (Input.GetKey(KeyCode.G))
        {
            key += 1;
        }

        UI_Key keys = GetComponent <UI_Key>();

        if (Input.GetKey(KeyCode.P))
        {
            keys.keyCount += 1;
        }

        // highlights gameObject if its a collectible and in range of raycast
        if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, distanceToSee))
        {
            if (hitInfo.transform.tag == "collectible" || hitInfo.transform.tag == "key")
            {
                // collect object and delete it from scene, adding +1 to inventory
                if (Input.GetKey(KeyCode.E))
                {
                    if (hitInfo.transform.tag == "key")
                    {
                        InteractionScript tresor = GetComponent <InteractionScript>();
                        tresor.safeKey = true;
                        keyForSafe     = true;
                        Debug.LogFormat("Keys: {0} ", key);
                    }

                    if (hitInfo.transform.tag == "collectible")
                    {
                        collectable += 1;
                        key         += 1;
                        Debug.LogFormat("collectibles: {0} ", collectable);
                    }
                    Destroy(hitInfo.collider.gameObject);
                }
                currRenderer = hitInfo.collider.gameObject.GetComponent <Renderer>();

                if (currRenderer == renderer)
                {
                    return;
                }

                if (currRenderer && currRenderer != renderer)
                {
                    if (renderer)
                    {
                        renderer.sharedMaterial = originalMaterial;
                    }
                }

                if (currRenderer)
                {
                    renderer = currRenderer;
                }
                else
                {
                    return;
                }

                originalMaterial = renderer.sharedMaterial;

                tempMaterial            = new Material(originalMaterial);
                renderer.material       = tempMaterial;
                renderer.material.color = highlightColor;
            }
            else
            {
                if (renderer)
                {
                    renderer.sharedMaterial = originalMaterial;
                    renderer = null;
                }
            }
        }
    }