public void updateDisplay(Ship_Class ship, int colorIndex) { this.ship = ship; switch (ship.getShipType()) { case "Frigate": shipInfoImage.sprite = frigateImages[colorIndex]; break; case "Cruiser": shipInfoImage.sprite = cruiserImages[colorIndex]; break; case "Battleship": shipInfoImage.sprite = battleshipImages[colorIndex]; break; case "Destroyer": shipInfoImage.sprite = destroyerImages[colorIndex]; break; case "Dreadnought": shipInfoImage.sprite = dreadnoughtImages[colorIndex]; break; } shipInfoImage.GetComponent <Image>().SetNativeSize(); Color temp = shipInfoImage.GetComponent <Image>().color; temp.a = 1f; shipInfoImage.GetComponent <Image>().color = temp; shipInfoText.text = ship.getShipType(); }
// Update is called once per frame void Update() { //print("HEY"); if (ships.Length == 0) //Set array length, after ships are initialized in Start { //print("Hey " + GameObject.FindObjectsOfType<Ship_Class>().Length); ships = new Ship_Class[GameObject.FindObjectsOfType <Ship_Class>().Length]; } if (true) //Find selected ships to populate ships[] { int j = 0; Ship_Class[] temp2 = GameObject.FindObjectsOfType <Ship_Class>(); foreach (Ship_Class i in temp2) { if (i != null && i.selected == true) { ships[j] = i; j++; } else { ships[j] = null; } } } //print(selector+" "+ships[selector]); if (ships[selector] != null) //If button has ship associated with it, select it { selected_ship = ships[selector]; } if (selected_ship != null) { //if(part2 != null) //print(part2.name + " " + (selected_ship.getShipType() + "(Clone)")); if (part2 == null || part2.name != (selected_ship.getShipType() + "(Clone)")) { part2 = Instantiate((GameObject)Resources.Load(selected_ship.getShipType()), this.transform); int h = 0; foreach (Button i in part2.GetComponentsInChildren <Button>()) { //print("Button " + i.name + " " + h); i.onClick.AddListener(() => install(int.Parse(i.name))); part_view[h] = i.GetComponent <Image>(); h++; } } int u = 0; //part_view = new Image[selected_ship.parts_list.Length]; foreach (Component_Class i in selected_ship.parts_list) { if (i != null) { part_view[u].sprite = i.getSprite(); } u++; } } //print("What up?"); if (Ship_list[0].GetComponentInParent <Canvas>().enabled == true) //If Canvas enabled, update UI { if (selected_ship != null) { Ship_list[0].text = selected_ship.name; } int k = 0; //print("YO " + ships[0]); foreach (Ship_Class i in ships) //Populate text for ships list { //print("YOU " + i.name); if (Ship_list[k + 1] != null) { //print("In if "+ships[k].name); if (ships[k] != null) { //print("Fill text box "+Ship_list[k+1].name+ " with "+i.name); Ship_list[k + 1].text = i.name; k++; } else { Ship_list[k + 1].text = ""; } } } //print(selected_ship); if (selected_ship != null) //If Canvas enabled and ship is selected, { //Find faction Shipyard and available components bool temp3 = true; Shipyard_Class[] temp; temp = GameObject.FindObjectsOfType <Shipyard_Class>(); foreach (Shipyard_Class i in temp) { if (selected_ship.pos == i.GetComponent <Transform>().position&& i.faction == selected_ship.faction) { print("truw"); inRange = i.component_storage; current = i; temp3 = false; } } if (temp3 == true) //If no shipyard found, set to -1 { inRange = new int[] { -1, -1, -1, -1, -1, -1, -1, -1 }; current = null; } } int p = 0; foreach (int i in inRange) { parts_avail[p].text = "" + i; p++; } } }