Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class PickUpItem : MonoBehaviour
  4. {
  5. public Item item;
  6. private Inventory _inventory;
  7. private GameObject _player;
  8. // Use this for initialization
  9.  
  10. void Start()
  11. {
  12. _player = GameObject.FindGameObjectWithTag("Player");
  13. if (_player != null)
  14. _inventory = _player.GetComponent<PlayerInventory>().inventory.GetComponent<Inventory>();
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if (_inventory != null && Input.GetKeyDown(KeyCode.E))
  21. {
  22. float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);
  23.  
  24. if (distance <= 1)
  25. {
  26. bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
  27. if (check) {
  28. Destroy (this.gameObject);
  29. }
  30. else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
  31. {
  32. _inventory.addItemToInventory(item.itemID, item.itemValue);
  33. _inventory.updateItemList();
  34. _inventory.stackableSettings();
  35. Destroy(this.gameObject);
  36. }
  37.  
  38. }
  39. }
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement