public void Change() { gameStateManager.ChangeGameState(stateName, stateValue, addInsteadSet); if (destroyAfterChange) { Destroy(this); } if (destroyGoAfterChange) { Grabable _grabable = this.gameObject.GetComponent <Grabable>(); if (!_grabable) { _grabable = this.gameObject.GetComponentInChildren <Grabable>(); } if (_grabable) { if (_grabable.myGrabee) { _grabable.myGrabee.grabableList.Remove(this.gameObject); _grabable.myGrabee.currentlyGrabbed = null; _grabable.myGrabee.ThrowGrabable(_grabable, Vector3.zero, false); } } } else if (coolDown > 0) { lastChangeTime = Time.time; } }
public void AddItemToInventorySlot(Grabable item, InventorySlot inventorySlot) { //check if the target inventory slot is still free, otherwise assign a random free one if (!freeInventorySlots.Contains(inventorySlot)) { int newIndex = Random.Range(0, freeInventorySlots.Count); inventorySlot = freeInventorySlots[newIndex]; freeInventorySlots.Remove(inventorySlot); } //set it to kinematic CHANGE in the future we might want physics behaviour within the inventory Rigidbody targetRig = item.myRig; if (targetRig) { targetRig.isKinematic = true; } item.grabAnchor.parent = inventorySlot.myTrans; item.grabAnchor.position = inventorySlot.myTrans.position; //we rotate so the items fit into the inventory slot item.grabAnchor.rotation = Quaternion.Euler(inventorySlot.myTrans.rotation.eulerAngles + item.inventoryRotationOffset); //and assign the currently grabbed item to that inventorySlot item.myInventorySlot = inventorySlot; inventorySlot.myItem = item; freeInventorySlots.Remove(inventorySlot); }
public void RemoveItemFromInventory(Grabable item) { foreach (InventorySlot inventorySlot in inventorySlots) { if (inventorySlot.myItem == item) { inventorySlot.myItem = null; freeInventorySlots.Add(inventorySlot); } } }
private void OnCollisionEnter(Collision collision) { if (changeOnCollision) { if (collision.gameObject.CompareTag(targetCollisionTag)) { if (coolDownTimer <= 0) { Change(); if (coolDown > 0) { coolDownTimer = coolDown; } if (destroyOtherGoAfterChange) { Grabable _grabable = collision.gameObject.GetComponent <Grabable>(); if (!_grabable) { _grabable = collision.gameObject.GetComponentInChildren <Grabable>(); } if (_grabable) { if (_grabable.myGrabee) { _grabable.myGrabee.grabableList.Remove(collision.gameObject); _grabable.myGrabee.currentlyGrabbed = null; _grabable.myGrabee.ThrowGrabable(_grabable, Vector3.zero, false); Destroy(collision.gameObject, Time.deltaTime); } } } } else { coolDownTimer = coolDown - (Time.time - lastChangeTime); } } } }