Advertisement
Kezoto

Untitled

Apr 4th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Inventory : MonoBehaviour
  6. {
  7. public List<GameObject> Items;
  8. public GameObject crowbar;
  9. public GameObject hand;
  10. public WeaponSettings weaponSettings;
  11. public float lomDamage = 30;
  12. public bool CanAddItem = true;
  13. public bool CanDrop = true;
  14. public float changeToolCooldown = 2f;
  15.  
  16. void Start()
  17. {
  18. weaponSettings = hand.GetComponent<WeaponSettings>();
  19. }
  20.  
  21. public void addItem(GameObject item)
  22. {
  23. if (Items.Count < 1 && CanAddItem)
  24. {
  25. CanAddItem = false;
  26. CanDrop = false;
  27. Items.Add(item);
  28. Rigidbody itemRigid = item.GetComponent<Rigidbody>();
  29. BoxCollider itemCollider = item.GetComponent<BoxCollider>();
  30. //itemCollider.isTrigger = true;
  31. itemRigid.useGravity = false;
  32. item.transform.parent = hand.transform;
  33. item.transform.position = hand.transform.position;
  34. item.transform.rotation = hand.transform.rotation;
  35. if (item.name == "lom")
  36. {
  37. weaponSettings.attackDamage = lomDamage;
  38. weaponSettings.weaponName = "lom";
  39. }
  40. StartCoroutine(OnCanDrop());
  41. StartCoroutine(OnCanAdd());
  42. }
  43. }
  44. private void Update()
  45. {
  46. if (Input.GetKeyDown("q"))
  47. {
  48. if (Items.Count > 0 && CanDrop)
  49. {
  50. CanAddItem = false;
  51. CanDrop = false;
  52. Items.RemoveRange(0, 1);
  53. GameObject narzedzie = hand.transform.GetChild(0).gameObject;
  54. Rigidbody narzedzieRigid = narzedzie.GetComponent<Rigidbody>();
  55. BoxCollider narzedzieCollider = narzedzie.GetComponent<BoxCollider>();
  56. // narzedzieCollider.isTrigger = false;
  57. narzedzieRigid.useGravity = true;
  58. narzedzie.transform.SetParent(null);
  59. weaponSettings.attackDamage = 0;
  60. weaponSettings.weaponName = "hand";
  61. StartCoroutine(OnCanDrop());
  62. StartCoroutine(OnCanAdd());
  63. }
  64. }
  65. }
  66.  
  67.  
  68.  
  69. IEnumerator OnCanAdd()
  70. {
  71. yield return new WaitForSeconds(changeToolCooldown);
  72. CanAddItem = true;
  73. }
  74.  
  75. IEnumerator OnCanDrop()
  76. {
  77. yield return new WaitForSeconds(changeToolCooldown);
  78. CanDrop = true;
  79. }
  80.  
  81.  
  82. Vector3 vector = new Vector3(1, 1, 1);
  83.  
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement