예제 #1
0
 public void UseItem(CollectableRef collRef)
 {
     Debug.Log("use item function");
     for (int i = 0; i < inventory.Count; i++)
     {
         if (collRef.name == "HP_potion_ref" || collRef.name == "HP_potion_50_ref")
         {
             if (playerHealthManager.playerCurrentHealth < playerHealthManager.playerMaxHealth)
             {
                 playerHealthManager.playerCurrentHealth += collRef.healPoints;
                 Instantiate(healEffect, thePlayer.transform.position, thePlayer.transform.rotation);
                 var clone = (GameObject)Instantiate(healNumber, thePlayer.transform.position, Quaternion.Euler(Vector3.zero));
                 clone.GetComponent <FloatingHealMoneyNumbers>().heal_or_money_number = collRef.healPoints;
                 //DestroyItemAfterUsage (collRef);
                 used = true;
                 if (playerHealthManager.playerCurrentHealth > playerHealthManager.playerMaxHealth)
                 {
                     playerHealthManager.playerCurrentHealth = playerHealthManager.playerMaxHealth;
                 }
                 return;
             }
             else
             {
                 used = false;
                 return;
             }
         }
     }
 }
예제 #2
0
 public void ChangeItem(CollectableRef newObject)
 {
     if (currObj != null)
     {
         Destroy(currObj);
         Debug.Log("Delete item");
     }
     currObj = GameObject.Instantiate(newObject.objectPrefab, new Vector3(thePlayer.transform.GetChild(0).transform.position.x, thePlayer.transform.GetChild(0).transform.position.y, thePlayer.transform.GetChild(0).transform.position.z), thePlayer.transform.GetChild(0).transform.rotation) as GameObject;
     currObj.transform.parent = thePlayer.transform.GetChild(0);
     equiped = true;
 }
예제 #3
0
 public void DestroyItemAfterUsage(CollectableRef collRef)
 {
     for (int i = 0; i < inventory.Count; i++)
     {
         if (inventory [i] == collRef)
         {
             inventory.Remove(collRef);
             return;
         }
     }
 }
예제 #4
0
    /*public void AddItem(Collectable newItem)
     * {
     *      //pickedupItem = newItem;
     *      temp=newItem.itemLogo;
     *      //pickedupItem=Collectable.Instantiate(newItem.gameObject,new Vector3 (transform.position.x, transform.position.y, transform.position.z), Quaternion.identity) as Collectable;
     *      for (int i = 0; i < texture.Length; i++)
     *      {
     *              if (texture[i] == null)
     *              {
     *                      texture [i] = temp;
     *                      return;
     *              }
     *      }
     *      //Destroy (newItem);
     * }*/

    void OnGUI()
    {
        GUILayout.BeginArea(rect);
        GUILayout.BeginHorizontal();

        foreach (CollectableRef collectableref in inventory)
        {
            if (collectableref != null)
            {
                if (GUILayout.Button(collectableref.objectImage, GUILayout.Width(50), GUILayout.Height(50)))
                {
                    //Instantiate (inventory[0], new Vector3 (transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
                    if (collectableref.names == "potion")
                    {
                        UseItem(collectableref);
                        if (used == true)
                        {
                            for (int i = 0; i < inventory.Count; i++)
                            {
                                if (inventory [i] == collectableref)
                                {
                                    DestroyItemAfterUsage(collectableref);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        currentObject = collectableref;
                        //currentObject.damage = collectableref.damage;
                        ChangeItem(collectableref);
                        //Object.Instantiate(collectableref.objectPrefab,transform.position,Quaternion.identity);
                        Debug.Log("Trenutni: " + currentObject);
                    }
                }
            }
            //if (GUILayout.Button ("del", GUILayout.Width (10), GUILayout.Height (10))) {
            //	DestroyItem (collectableref);
            //}
            //Destroy (currentObject);
            //GameObject.Instantiate(currentObject,new Vector3 (transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
        }

        GUILayout.EndArea();
        GUILayout.EndHorizontal();
    }