Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Inventory : MonoBehaviour
- {
- public List<GameObject> Items;
- public GameObject crowbar;
- public GameObject hand;
- public WeaponSettings weaponSettings;
- public float lomDamage = 30;
- public bool CanAddItem = true;
- public bool CanDrop = true;
- public float changeToolCooldown = 2f;
- void Start()
- {
- weaponSettings = hand.GetComponent<WeaponSettings>();
- }
- public void addItem(GameObject item)
- {
- if (Items.Count < 1 && CanAddItem)
- {
- CanAddItem = false;
- CanDrop = false;
- Items.Add(item);
- Rigidbody itemRigid = item.GetComponent<Rigidbody>();
- BoxCollider itemCollider = item.GetComponent<BoxCollider>();
- //itemCollider.isTrigger = true;
- itemRigid.useGravity = false;
- item.transform.parent = hand.transform;
- item.transform.position = hand.transform.position;
- item.transform.rotation = hand.transform.rotation;
- if (item.name == "lom")
- {
- weaponSettings.attackDamage = lomDamage;
- weaponSettings.weaponName = "lom";
- }
- StartCoroutine(OnCanDrop());
- StartCoroutine(OnCanAdd());
- }
- }
- private void Update()
- {
- if (Input.GetKeyDown("q"))
- {
- if (Items.Count > 0 && CanDrop)
- {
- CanAddItem = false;
- CanDrop = false;
- Items.RemoveRange(0, 1);
- GameObject narzedzie = hand.transform.GetChild(0).gameObject;
- Rigidbody narzedzieRigid = narzedzie.GetComponent<Rigidbody>();
- BoxCollider narzedzieCollider = narzedzie.GetComponent<BoxCollider>();
- // narzedzieCollider.isTrigger = false;
- narzedzieRigid.useGravity = true;
- narzedzie.transform.SetParent(null);
- weaponSettings.attackDamage = 0;
- weaponSettings.weaponName = "hand";
- StartCoroutine(OnCanDrop());
- StartCoroutine(OnCanAdd());
- }
- }
- }
- IEnumerator OnCanAdd()
- {
- yield return new WaitForSeconds(changeToolCooldown);
- CanAddItem = true;
- }
- IEnumerator OnCanDrop()
- {
- yield return new WaitForSeconds(changeToolCooldown);
- CanDrop = true;
- }
- Vector3 vector = new Vector3(1, 1, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement