private void OnEnable() { if (playerManagerScript == null) { playerManagerScript = GameObject.FindObjectOfType <PlayerManagerScript>(); } if (inventoryUIScript == null) { inventoryUIScript = GameObject.FindObjectOfType <InventoryUIScript>(); } unitStatesDisplayScript.updateStates(playerManagerScript.units[0]); }
public void SetupInventory(GameObject playerUIObj) { inventory = new Dictionary <string, GameObject[]>() { { PRIMARY, new GameObject[] { null } }, { SECONDARY, new GameObject[] { null } }, { KNIFE, new GameObject[] { null } }, { GRENADES, new GameObject[] { null, null, null, null } }, { BOMB, new GameObject[] { null } } }; //see if there are weapons currently parented to the inventory management item for (int i = 0; i < this.transform.childCount; i++) { GameObject child = this.transform.GetChild(i).gameObject; if (child.GetComponent <Weapon>() != null) { child.GetComponent <Rigidbody>().useGravity = false; child.GetComponent <Rigidbody>().isKinematic = true; child.GetComponent <Rigidbody>().detectCollisions = false; child.GetComponent <Collider>().enabled = false; inventory[child.GetComponent <Weapon>().weaponSlot][0] = child; //always position 0 because there is only one item for these slots } else if (child.GetComponent <Grenades>() != null) { child.GetComponent <Rigidbody>().useGravity = false; child.GetComponent <Rigidbody>().isKinematic = true; child.GetComponent <Rigidbody>().detectCollisions = false; child.GetComponent <Collider>().enabled = false; //loop over four game object spots for grenades for (int j = 0; j < 4; j++) { if (inventory[child.GetComponent <Grenades>().weaponSlot][j] == null) { inventory[child.GetComponent <Grenades>().weaponSlot][j] = child; break; } } } } if (playerUIObj != null) { inventoryUi = playerUIObj.GetComponent <InventoryUIScript>(); } }
/** * Start function. Need to do the following: * - Initialize variables only if the game objects have been set * - Get the default icon which is "Background" */ public void StartMe() { selected = false; if (UiSlot != null) uiSlotImage = UiSlot.GetComponent<Image>(); if (ContextAwareBox != null) contextBoxScript = ContextAwareBox.GetComponent<ContextAwareBox>(); if (Container != null) containerScript = Container.GetComponent<InventoryUIScript>(); }
//Update UI public void setInventoryUI(InventoryUIScript i) { inventoryUIScript = i; }