コード例 #1
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.E) && selectQ.GetSelected() > -1 && plantable)
     {
         KeyValuePair <GameObject, int> test = quickSlot.GetItemAndAmount(selectQ.GetSelected());
         if (test.Key && test.Key.GetComponent <Seed>())
         {
             GameObject copy = Instantiate(test.Key, transform.position, Quaternion.identity) as GameObject;
             quickSlot.Remove(test.Key.GetComponent <PickableItem>().itemName, 1);
             quickUI.UpdateQuickSlot();
             plantable = false;
             copy.GetComponent <Seed>().planted = true;
         }
     }
 }
コード例 #2
0
 //Detects when an item is "picked up" by the player
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player" && playerIn)
     {
         GameObject copy = Instantiate(this.gameObject, new Vector3(0, 0, -15), Quaternion.identity) as GameObject;
         Destroy(copy.GetComponent <BoxCollider2D>());
         if (playerQ.Add(copy, amountToGive))
         {
             quickSlot.UpdateQuickSlot();
             Destroy(this.gameObject);
         }
         else if (playerIn.Add(copy, amountToGive))
         {
             mainInventory.UpdateInventory();
             Destroy(this.gameObject);
         }
         else
         {
             Destroy(copy);
         }
     }
 }