public void Insert(IsEquipable equipObj) { if (obj == null) { obj = equipObj; obj.transform.parent = this.transform; obj.transform.localPosition = Vector3.zero; // dhdh - attach directly to TForm of slot obj.transform.localRotation = Quaternion.identity; // enable collider //obj.gameObject.collider.enabled = true; obj.gameObject.collider2D.enabled = true; //obj.rigidbody.useGravity = false; //obj.rigidbody.isKinematic = true; obj.rigidbody2D.isKinematic = true; // turn on renderers if (obj.gameObject.renderer) { obj.gameObject.renderer.enabled = true; } // get all child renderer components and disable them Renderer[] renderers = GetComponentsInChildren <Renderer>() as Renderer[]; foreach (Renderer r in renderers) { r.enabled = true; } } }
public bool AddToInventory(GameObject newParent) { InventoryData[] inventories = newParent.GetComponentsInChildren <InventoryData>(); for (int i = 0; i < inventories.Length; i++) { if (inventories[i].inventoryName == this.inventoryName) { CollectionData collection = inventories[i].GetCollectionByName(collectionName); if (collection != null) { collection.Insert(this); this.gameObject.SetActive(false); // check for other mixins here? IsEquipable equipable = this.GetComponent <IsEquipable>(); if (equipable) { equipable.AttachToSlot(newParent); } return(true); } else { Debug.Log("No collection " + collectionName + " on touched GameObject " + newParent.name + "."); return(false); } } } Debug.Log("No inventory " + inventoryName + " on touched GameObject " + newParent.name + "."); return(false); }
public void TryEquip(IsEquipable equipment) { if (currentEquip == null) { currentEquip = equipment; equipment.gameObject.SetActive(true); } }
public void AddEquipment(IsEquipable equipment) { // ensure only one of each equipment name for (int i = 0; i < attachedEquipment.Count; i++) { if (attachedEquipment[i].Name == equipment.Name) { Destroy(equipment.gameObject); return; } } // add equipment to list attachedEquipment.Add(equipment); }
public void Remove() { // turn off renderers if (obj.gameObject.renderer) { obj.gameObject.renderer.enabled = false; } // get all child renderer components and disable them Renderer[] renderers = GetComponentsInChildren <Renderer>() as Renderer[]; foreach (Renderer r in renderers) { r.enabled = false; } obj.transform.parent = null; obj = null; }
public void OnCollisionEnter(Collision col) { // Check if this weapon is equipped IsEquipable eq = GetComponent <IsEquipable>(); if (eq) { // check for eq if (eq.isEquip()) { // CHECK IF IT HAS AN ISDAMAGABLE COMP?? IsDamageable dmg = col.gameObject.GetComponent <IsDamageable>(); if (dmg) { dmg.TakeDamage(msg); } } } }
public void Equip(IsEquipable equipment) { if (currentEquip == null) { currentEquip = equipment; equipment.gameObject.SetActive(true); } else if (currentEquip.Name == equipment.Name) { currentEquip = null; equipment.gameObject.SetActive(false); } else { currentEquip.gameObject.SetActive(false); currentEquip = equipment; currentEquip.gameObject.SetActive(true); } }