Example #1
0
    private void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            if (playerClick())
            {
                scr_Inventory playerInventory = other.GetComponent <scr_Inventory>();
                scr_KeyData   keyUsed         = playerInventory.activeKey; //Get active (used) key data from player inventory

                if (!active)                                               //put key on portal recepticle
                {
                    if (keyUsed != null)
                    {
                        if (keyUsed.transform.root != transform.root)
                        {
                            GameObject.FindGameObjectWithTag("UI").GetComponent <scr_UI>()
                            .displayMsg("Some force is pushing the key back...");
                            return;
                        }

                        active    = true;
                        keyPlaced = keyUsed.spawn(transform, false);
                        keyPlaced.GetComponent <BoxCollider>().isTrigger = false;

                        playerInventory.removeKey(keyUsed);

                        showUseText();

                        updateLift(-1);
                    }
                }

                else if (keyPlaced) //take key from portal recepticle
                {
                    scr_KeyData keyData = keyPlaced.GetComponent <scr_PortalKeyPickUp>().keyData;
                    playerInventory.addKey(keyData); //Add the data from the pickup back to player inventory
                    active = false;
                    Destroy(keyPlaced);

                    updateLift(1);
                }
            }
        }
    }
Example #2
0
    private void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            if (playerClick())
            {
                scr_Inventory playerInventory = other.GetComponent <scr_Inventory>();
                if (!transform.parent.GetComponent <scr_PortGate>().active) //put key on portal recepticle
                {
                    scr_KeyData keyUsed = playerInventory.activeKey;        //Get active (used) key data from player inventory

                    if (keyUsed != null)
                    {
                        if (keyUsed.transform.GetComponentInParent <scr_PortGate>().active)
                        {
                            GameObject.FindGameObjectWithTag("UI").GetComponent <scr_UI>().displayMsg("Some force is pushing the key back...");
                            return;
                        }

                        transform.parent.GetComponent <scr_PortGate>().activatePortal(keyUsed);
                        keyPlaced = keyUsed.spawn(transform, true);
                        keyPlaced.transform.GetChild(0).localPosition = new Vector3(.1f, 0, 0); //Change symbol position

                        playerInventory.removeKey(keyUsed);

                        showUseText();
                    }
                }
                else if (keyPlaced) //take key from portal recepticle
                {
                    scr_KeyData keyData = keyPlaced.GetComponent <scr_PortalKeyPickUp>().keyData;
                    playerInventory.addKey(keyData); //Add the data from the pickup back to player inventory
                    transform.parent.GetComponent <scr_PortGate>().deactivatePortal(keyData);
                    Destroy(keyPlaced);
                    showUseText();
                }
            }
        }
    }