Advertisement
Kezoto

Untitled

Mar 29th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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. if (itemCollider.isTrigger == true && itemRigid.useGravity == false)
  33. {
  34. item.transform.parent = hand.transform;
  35. item.transform.position = hand.transform.position;
  36. item.transform.rotation = hand.transform.rotation;
  37. if (item.name == "lom")
  38. {
  39. weaponSettings.attackDamage = lomDamage;
  40. weaponSettings.weaponName = "lom";
  41. }
  42. }
  43. StartCoroutine(OnCanDrop());
  44. StartCoroutine(OnCanAdd());
  45. }
  46. }
  47. private void Update()
  48. {
  49. if (Input.GetKeyDown("q"))
  50. {
  51. if (Items.Count > 0 && CanDrop)
  52. {
  53. CanAddItem = false;
  54. CanDrop = false;
  55. Items.RemoveRange(0, 1);
  56. GameObject narzedzie = hand.transform.GetChild(0).gameObject;
  57. Rigidbody narzedzieRigid = narzedzie.GetComponent<Rigidbody>();
  58. BoxCollider narzedzieCollider = narzedzie.GetComponent<BoxCollider>();
  59. narzedzieCollider.isTrigger = false;
  60. narzedzieRigid.useGravity = true;
  61. narzedzie.transform.SetParent(null);
  62. weaponSettings.attackDamage = 0;
  63. weaponSettings.weaponName = "hand";
  64. StartCoroutine(OnCanDrop());
  65. StartCoroutine(OnCanAdd());
  66. }
  67. }
  68. }
  69.  
  70.  
  71.  
  72. IEnumerator OnCanAdd()
  73. {
  74. yield return new WaitForSeconds(changeToolCooldown);
  75. CanAddItem = true;
  76. }
  77.  
  78. IEnumerator OnCanDrop()
  79. {
  80. yield return new WaitForSeconds(changeToolCooldown);
  81. CanDrop = true;
  82. }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement