private void Update()
 {
     //add new bag
     if (Input.GetKeyDown(KeyCode.H))
     {
         Bag bag = (Bag)Instantiate(items[0]);
         bag.Initalize(8);
         bag.Use();
     }
     //add new 16 slot bag
     if (Input.GetKeyDown(KeyCode.J))
     {
         Bag bag = (Bag)Instantiate(items[0]);
         bag.Initalize(16);
         AddItem(bag);
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         HealthPortion portion = (HealthPortion)Instantiate(items[1]);
         AddItem(portion);
     }
     if (Input.GetKeyDown(KeyCode.L))
     {
         HealthPortion portion = (HealthPortion)Instantiate(items[2]);
         AddItem(portion);
     }
 }
예제 #2
0
    public void OnTriggerEnter2D(Collider2D collision)
    //public void OnCollisionEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            //if (Input.GetMouseButtonDown(1))
            //{
            if (this.gameObject.name == "Bag")
            {
                Bag bag = (Bag)Instantiate(typeCollect);
                bag.Initalize(bagSize);
                InventoryScript.MyInstance.AddItem(bag);
                this.gameObject.SetActive(false);
            }

            else if (this.gameObject.name == "Sword")
            {
                Weapon weapon = (Weapon)Instantiate(typeCollect);
                InventoryScript.MyInstance.AddItem(weapon);
                this.gameObject.SetActive(false);
            }

            else
            {
                HealthPortion portion = (HealthPortion)Instantiate(typeCollect);
                InventoryScript.MyInstance.AddItem(portion);
                this.gameObject.SetActive(false);
            }
            // IsAdded = true;
            //}
        }
    }