private void CreateInventorySlotsInWindow() { for (int i = 0; i < listNumber; i++)//fills the fleet inventory list (change 20 to the size of the players fleet) { itemSlot = (GameObject)Instantiate(itemSlotPrefab); itemSlot.name = i.ToString(); itemText = itemSlot.GetComponentInChildren <Text>() as Text; itemText.text = testlist[i]; testShip = playerInventory.AccessShip(i); itemImagePos = itemSlot.GetComponentInChildren <Image>(); //position to place ship image attached to itemSlotPrefab itemImage = testShip.GetComponent <Image>(); //image of ship attached to ship prefab itemImageSprite = itemImage.sprite; //the sprite of the image of the ship attached to ship prefab itemImagePos.sprite = itemImageSprite; //sets the posision image to be equal to the ship image //itemImagePos = itemImage; //itemImagePos = testShip.GetComponent<Image>() as Image; itemSlot.GetComponent <Toggle>().group = itemSlotToggleGroup; itemSlot.transform.SetParent(content.transform); itemSlot.GetComponent <RectTransform>().localPosition = new Vector3(xPos, yPos, 0); yPos -= (int)itemSlot.GetComponent <RectTransform>().rect.height; } for (int i = 0; i < 4; i++)//fills the extra space at the bottom { itemSlot = (GameObject)Instantiate(emptyItemSlotPrefab); itemSlot.name = i.ToString(); itemSlot.GetComponent <Toggle>().group = itemSlotToggleGroup; itemSlot.transform.SetParent(content.transform); itemSlot.GetComponent <RectTransform>().localPosition = new Vector3(xPos, yPos, 0); yPos -= (int)itemSlot.GetComponent <RectTransform>().rect.height; } }
// Update is called once per frame void Update() { selectedShip = PlayerPrefs.GetInt("selectedShip"); testShip = playerInventory.AccessShip(selectedShip); itemImage = testShip.GetComponent <Image>(); //image of ship attached to ship prefab itemSprite = itemImage.sprite; //the sprite of the image of the ship attached to ship prefab spritePositionImage.sprite = itemSprite; //sets the posision image to be equal to the ship image }
public void CreateFleet() { for (int i = 1; i < fleetSize; i++) { int testint = battleFormation[i]; Debug.Log(battleFormation[i]); GameObject testobject = m_player_inven.AccessShip(testint); if (battleFormation[i] != 0) { currentPlayerFleet._Add_To_Fleet(testobject); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { currentlySelected.SetActive(false); shipStats.SetActive(false); fleetInventory.SetActive(false); //hides current menus fleet.SetActive(true); prebattleSetup.SetActive(true); //shows the previous menus } if (Input.GetKeyDown(KeyCode.E)) { //formationindex=selectedship GameObject preBattleState = GameObject.Find("PreBattleState"); preBattleState.GetComponent <PreBattleState>().setInventoryIndex(PlayerPrefs.GetInt("selectedShip")); preBattleState.GetComponent <PreBattleState>().setBattleFormation(); GameObject testShip = playerInventory.AccessShip(preBattleState.GetComponent <PreBattleState>().battleFormation[preBattleState.GetComponent <PreBattleState>().getFormationIndex()]); Image shipImage = testShip.GetComponent <Image>(); targetImage.sprite = shipImage.sprite; } }
void UpdateShipText() { if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.W)) { currentShip = playerInventory.AccessShip(PlayerPrefs.GetInt("selectedShip")).GetComponent <publicShip>().ShipClass; string[] x = currentShip.s_Get_Names(); float[] y = currentShip.s_Get_Val(); text[0].text = testlist[selectedShip]; text[1].text = x[1]; text[2].text = y[0].ToString(); text[3].text = y[1].ToString(); text[4].text = y[2].ToString(); text[5].text = y[3].ToString(); text[6].text = y[4].ToString(); //for (int i = 0; i < 5; i++) //{ /* * weapontext[0].text = currentShip.s_Weapons[0].name.ToString(); * weapontext[1].text = currentShip.s_Weapons[0].w_Get_Dam_H().ToString(); * weapontext[2].text = currentShip.s_Weapons[0].w_Get_Dam_S().ToString(); * weapontext[3].text = currentShip.s_Weapons[0].w_Type.ToString(); * weapontext[4].text = currentShip.s_Weapons[0].w_Ammo.ToString(); * } */ if (currentShip.s_Weapons[0] != null) { weapontext1[0].text = currentShip.s_Weapons[0].name.ToString(); weapontext1[1].text = currentShip.s_Weapons[0].w_Get_Dam_H().ToString(); weapontext1[2].text = currentShip.s_Weapons[0].w_Get_Dam_S().ToString(); weapontext1[3].text = currentShip.s_Weapons[0].w_Type.ToString(); weapontext1[4].text = currentShip.s_Weapons[0].w_Ammo.ToString(); } if (currentShip.s_Weapons[1]) { weapontext2[0].text = currentShip.s_Weapons[1].name.ToString(); weapontext2[1].text = currentShip.s_Weapons[1].w_Get_Dam_H().ToString(); weapontext2[2].text = currentShip.s_Weapons[1].w_Get_Dam_S().ToString(); weapontext2[3].text = currentShip.s_Weapons[1].w_Type.ToString(); weapontext2[4].text = currentShip.s_Weapons[1].w_Ammo.ToString(); } if (currentShip.s_Weapons[2] != null) { weapontext3[0].text = currentShip.s_Weapons[2].name.ToString(); weapontext3[1].text = currentShip.s_Weapons[2].w_Get_Dam_H().ToString(); weapontext3[2].text = currentShip.s_Weapons[2].w_Get_Dam_S().ToString(); weapontext3[3].text = currentShip.s_Weapons[2].w_Type.ToString(); weapontext3[4].text = currentShip.s_Weapons[2].w_Ammo.ToString(); } if (currentShip.s_Weapons[3] != null) { weapontext4[0].text = currentShip.s_Weapons[3].name.ToString(); weapontext4[1].text = currentShip.s_Weapons[3].w_Get_Dam_H().ToString(); weapontext4[2].text = currentShip.s_Weapons[3].w_Get_Dam_S().ToString(); weapontext4[3].text = currentShip.s_Weapons[3].w_Type.ToString(); weapontext4[4].text = currentShip.s_Weapons[3].w_Ammo.ToString(); } } }