Пример #1
0
    void Update()
    {
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            //Check if it can be stored in inventory
            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
            }

            //Check to see if object can be opened
            if (currentInterObjScript.openable)
            {
                //check if it's locked
                if (currentInterObjScript.locked)
                {
                    //check if we have object needed to unlock
                    //search inventory for item needed - if found, unlock object
                    if (inventory.FindItem(currentInterObjScript.itemNeeded))
                    {
                        //found item needed, unlock thing
                        currentInterObjScript.locked = false;
                        Debug.Log(currentInterObj.name + " was unlocked");
                    }
                    else
                    {
                        Debug.Log(currentInterObj.name + " was not unlocked");
                    }
                }
                else
                {
                    //object is not locked - open the object
                    Debug.Log(currentInterObj.name + " is unlocked");
                    currentInterObjScript.Open();
                }
            }

            //Check if object talks and has a message
            if (currentInterObjScript.talks)
            {
                //tell the object to give its message
                currentInterObjScript.Talk();
            }
        }
        //Eat an item
        if (Input.GetButtonDown("Remove"))
        {
            //check inventory for an edible item
            GameObject edible = inventory.FindItemByType("Edible");
            if (edible != null)
            {
                Debug.Log("nom nom nom nom nom nom nom nom");
                inventory.RemoveItem(edible);
            }
        }
    }
Пример #2
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Interact") && currentInterObj)
     {
         //Check to see if this object is to be stored in inventory
         if (currentInterObjScript.inventory)
         {
             inventory.AddItem(currentInterObj);
         }
         // check to see if this object can be opened;
         if (currentInterObjScript.openable)
         {
             //check to see  if the object is locked
             if (currentInterObjScript.locked)
             {
                 //check  to see if we have object  needed to unlock;
                 //Search our inventory for the item needed - if found unlock object
                 if (inventory.FindItem(currentInterObjScript.itemNeeded))
                 {
                     //We found the item needed
                     currentInterObjScript.locked = false;
                     Debug.Log(currentInterObj.name + "was unlocked");
                 }
                 else
                 {
                     Debug.Log(currentInterObj.name + "was not unlocked");
                 }
             }
             else
             {
                 //object is not locked  - open the object
                 Debug.Log(currentInterObj.name + "is unlocked");
                 currentInterObjScript.Open();
             }
         }
     }
     //Use a potion
     if (Input.GetButtonDown("Use Potion"))
     {
         GameObject potion = inventory.FindItemByType("Health Potion");
         if (potion != null)
         {
             inventory.RemoveItem(potion);
             thePHM.playerCurrentHealth += 10;
             if (thePHM.playerCurrentHealth > thePHM.playerMaxHealth)
             {
                 thePHM.playerCurrentHealth = thePHM.playerMaxHealth;
             }
             Debug.Log("Health Potion was used");
         }
         else
         {
             Debug.Log("Health Potion Not in the inventory");
         }
     }
 }
Пример #3
0
    void Update()
    {
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            //Check to see if the object is to be store in the inventory
            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
                currentInterObj = null;
            }
            //Check to see if can be opened
            if (currentInterObjScript.openable)
            {
                //Check to see if locked
                if (currentInterObjScript.locked)
                {
                    //checking if the needed item is in the inventory
                    if (inventory.FindItem(currentInterObjScript.itemNeeded))
                    {
                        Debug.Log("Opening the door");
                        //Open the door
                        currentInterObjScript.locked = false;
                        //play the open animation
                        currentInterObjScript.Open();
                        //remove key after use
                        inventory.RemoveItem(currentInterObjScript.itemNeeded);
                    }
                    else
                    {
                        Debug.Log("U dont have the key");
                    }
                }
                else
                {
                    Debug.Log("Door is open");
                    //Door is already open close it
                }
            }
        }
        if (Input.GetButtonDown("Use Potion"))
        {
            //check the inv for a potion
            GameObject potion = inventory.FindItemByType("Hpotion");
            if (potion != null)
            {
                //Use the potion and add health

                //Remove the potion
                inventory.RemoveItem(potion);
            }
        }
    }
    void Update()
    {
        // If player presses 'e' and that object is the current interactable object (in object trigger point)
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            // If player has interacted with a medkit and is bleeding from the monster
            if (currentInterObjScript.IsMedkit() && GetComponent <Bleeding>().bleeding)
            {
                // Stops the player from bleeding, resets timer back to 120 and disables it, plays a sound and removes medkit from game
                GetComponent <Bleeding>().bleeding          = false;
                GetComponent <Bleeding>().timer             = 120;
                GetComponent <Bleeding>().Countdown.enabled = false;
                audioSource.PlayOneShot(heal);
                currentInterObj.SetActive(false);
            }
            else
            {
                //Alert player they can't use medkit
            }

            // If the item is an item that can be put in the inventory
            if (currentInterObjScript.inventory)
            {
                // Adds the item to the inventory, removes the item from game, plays sound, adds 1 to the counter and displays it to player.
                inventory.AddItem(currentInterObj);
                currentInterObjScript.DoInteraction();
                audioSource.clip  = keys;
                audioSource.pitch = 1.5f;
                audioSource.Play();
                count = count + 1;
                SetCountText();
                Debug.Log(currentInterObj.activeInHierarchy);
            }
            // uses tags to check which note in particular has been interacted with
            if (currentInterObj.CompareTag("Note"))
            {
                Debug.Log("inside");
                // shows that specific note the player interacts with
                currentInterObj.GetComponent <Note>().ShowNoteImage();
            }
            if (currentInterObj.CompareTag("otherNote"))
            {
                Debug.Log("inside");
                currentInterObj.GetComponent <Note1>().ShowNoteImage();
            }
            if (currentInterObj.CompareTag("otherNote1"))
            {
                Debug.Log("inside");
                currentInterObj.GetComponent <Note2>().ShowNoteImage();
            }
            if (currentInterObj.CompareTag("otherNote2"))
            {
                Debug.Log("inside");
                currentInterObj.GetComponent <Note3>().ShowNoteImage();
            }
            if (currentInterObj.CompareTag("otherNote3"))
            {
                Debug.Log("inside");
                currentInterObj.GetComponent <Note4>().ShowNoteImage();
            }

            // checks if the interactable object can be opened (eg. doors)
            if (currentInterObjScript.openable)
            {
                // checks if door is locked
                if (currentInterObjScript.locked)
                {
                    // checks if player has a key in their inventory
                    if (inventory.FindKey())
                    {
                        // key is found in inventory: door is unlocked, plays animation, removes 1 from the counter and shows player, plays sound.
                        currentInterObjScript.locked = false;
                        Debug.Log(currentInterObj.name + " was unlocked");
                        currentInterObjScript.Open();
                        count = count - 1;
                        SetCountText();
                        currentInterObjScript.DoInteraction();
                        audioSource.clip  = dooropening;
                        audioSource.pitch = 1f;
                        audioSource.PlayOneShot(dooropening);
                    }
                    else
                    {
                        // key was not found: door stays locked and plays sound.
                        Debug.Log("locked");
                        currentInterObjScript.locked = true;
                        audioSource.clip             = doorlocked;
                        audioSource.pitch            = 1f;
                        audioSource.Play();
                        Debug.Log(currentInterObj.name + " was not unlocked");
                    }
                }
                else
                {
                    Debug.Log(currentInterObj.name + " is open");
                }
            }

            currentInterObj = null;
        }
    }
Пример #5
0
    //changing this to public to see if it changes anything with interactionobject
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            Damage(1);
            inEnemies++;
        }
        else if (collision.gameObject.tag == "Powerup")
        {
            collision.gameObject.SendMessage("Pickup", heldPowerup);
            switch (heldPowerup[0])
            {
            case PowerupType.TELEBACK:
                tutText.pushToMin(4);
                this.GetComponent <Shooting>().telebackUnlocked = true;
                GameObject.Find("EnemyManager").GetComponent <EnemyManager>().currentGameState = 1;
                break;

            case PowerupType.CHARGE_SHOT:
                tutText.pushToMin(6);
                this.GetComponent <Shooting>().chargeShotUnlocked = true;
                GameObject.Find("EnemyManager").GetComponent <EnemyManager>().currentGameState = 2;
                break;

            case PowerupType.STUN:
                tutText.pushToMin(8);
                this.GetComponent <Shooting>().stunUnlocked = true;
                GameObject.Find("EnemyManager").GetComponent <EnemyManager>().currentGameState = 2;
                break;

            case PowerupType.INVINC:
                GameObject.Find("Boss").GetComponent <Boss>().vulnerable = true;
                tutText.pushToMin(9);
                break;
            }
        }
        if (collision.CompareTag("InteractionObject"))
        {
            currentInterObj       = collision.gameObject;
            currentInterObjScript = currentInterObj.GetComponent <InteractionObject>();
        }

        //interaction with InteractionObjects;
        if (collision.gameObject.tag == "InteractionObject" && currentInterObj)
        {
            //check if you can put it in inventory
            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
                print("item added to inventory");
            }
            if (currentInterObjScript.openable)
            {
                if (currentInterObjScript.locked)
                {
                    //check to see if we have the object needed
                    //search inventory, if found, unlock object
                    if (inventory.FindItem(currentInterObjScript.itemNeeded))
                    {
                        //we found item needed
                        currentInterObjScript.locked = false;
                        print(currentInterObj.name + " was unlocked");
                    }
                    else
                    {
                        print(currentInterObj.name + " was not unlocked");
                    }
                }
                else
                {
                    print(currentInterObj.name + " is unlocked");
                    currentInterObjScript.Open();
                }
            }
        }
    }