void Spawn(int ind, float y) { Instantiate(TroopAvatar, new Vector3(gameObject.transform.position.x + ((float)Screen.width / 840) * (distance + (ind % 9) * distance), gameObject.transform.position.y - ((float)Screen.height / 473) * y, gameObject.transform.position.z), Quaternion.identity); avatars = GameObject.FindGameObjectsWithTag("avatar"); avatars [avatars.Length - 1].transform.SetParent(overlord.transform.parent); avatars [avatars.Length - 1].transform.localScale = new Vector3(1, 1, 1); buttonscript = avatars [avatars.Length - 1].GetComponentInChildren <TroopButton> (); buttonscript.order = ind; objscript = troops [ind].GetComponent <ChangelingTroop> (); if (objscript.tip == "Villager") { buttonscript.gameObject.GetComponent <Button> ().spriteState = Changeling; buttonscript.gameObject.GetComponent <Image> ().sprite = Changeling.disabledSprite; goto nexte2; } if (objscript.tip == "Ponies-At-Arms") { buttonscript.gameObject.GetComponent <Button> ().spriteState = PoniesAtArms; buttonscript.gameObject.GetComponent <Image> ().sprite = PoniesAtArms.disabledSprite; goto nexte2; } nexte2: objscript.GUILbar = avatars [avatars.Length - 1].GetComponentInChildren <LifeBar> (); objscript.GUILbar.reflectlief = troops [ind].GetComponent <ChangelingTroop> (); nexte3 :; }
void Start() //SET STUFF { objscript = gameObject.GetComponentInParent <ChangelingTroop>(); if (!objscript.building) { OurCollider = gameObject.GetComponent <BoxCollider> (); motherscript = gameObject.GetComponentInParent <ChangelingTroop> (); } else { OurColliderMesh = gameObject.GetComponent <MeshCollider> (); } }
public void setoffsets() { if (formscript.LX.Count >= 1 && formscript.LZ.Count >= 1) //THERE WAS ENOUGH ONLY ONE COUNT CHECK, BUT I DID 2 FOR A MORE SUGGESTIVE IF { formscript.LX.Sort(); formscript.LZ.Sort(); for (int i = 1; i <= formation.transform.childCount - 1; i++) { troopscript = formation.transform.GetChild(i).GetComponent <ChangelingTroop> (); troopscript.offsetX = (formscript.LX [formscript.LX.Count - 1] + formscript.LX [0]) / 2 - troopscript.gameObject.GetComponentInChildren <Selectable> ().origX; troopscript.offsetZ = (formscript.LZ [formscript.LZ.Count - 1] + formscript.LZ [0]) / 2 - troopscript.gameObject.GetComponentInChildren <Selectable> ().origZ; } } }
void Update() { ray = Camera.main.ScreenPointToRay(Input.mousePosition); Physics.Raycast(ray, out hitDUDE, Mathf.Infinity); if (Input.GetMouseButtonDown(1) && SelectionLines.validmouse) { if (hitDUDE.collider.tag == "Terra") { if (SelectedTroops.TotalNB >= 1) { moveX.transform.position = new Vector3(hitDUDE.point.x + 0.1f, hitDUDE.point.y + 0.3f, hitDUDE.point.z - 0.1f); moveXanim.SetBool("begin", true); Invoke("SetMoveXfalse", 0.1f); } } else { if (SelectedTroops.ChangelingsNB >= 1) { targetanim = hitDUDE.collider.transform.GetChild(0).GetComponent <Animator> (); targetanim.SetBool("sel", true); Invoke("SetSelfalse", 0.05f); surroundSquare = hitDUDE.collider.gameObject.transform.GetChild(1).GetComponent <BoxCollider> (); } } for (int i = 1; i <= formation.transform.childCount - 1; i++) { troopscript = formation.transform.GetChild(i).GetComponent <ChangelingTroop> (); troopscript.job = 0; troopscript.job0(); if (hitDUDE.collider.tag != "Terra" && troopscript.tip == "Villager") { surroundSquare = hitDUDE.collider.GetComponent <BoxCollider> (); if (hitDUDE.collider.tag == "vine") { troopscript.job = 1; } if (hitDUDE.collider.tag == "AppleTree") { troopscript.currentgather = hitDUDE.collider.gameObject; troopscript.job = 2; } if (hitDUDE.collider.tag == "FoodDrop") { if (troopscript.food > 0) { troopscript.job = -2; troopscript.CancelInvoke("gatherFood"); } troopscript.target = hitDUDE.collider; troopscript.gototarget(hitDUDE.collider.gameObject); goto endDrop; } troopscript.target = surroundSquare; rand = Random.Range(1, 5); if (rand % 4 == 0) { troopscript.movDESTINATION = new Vector3(Random.Range(surroundSquare.bounds.center.x - surroundSquare.bounds.extents.x, surroundSquare.bounds.center.x + surroundSquare.bounds.extents.x), hitDUDE.point.y, surroundSquare.bounds.center.z - surroundSquare.bounds.extents.z); } if (rand % 4 == 1) { troopscript.movDESTINATION = new Vector3(surroundSquare.bounds.center.x - surroundSquare.bounds.extents.x, hitDUDE.point.y, Random.Range(surroundSquare.bounds.center.z - surroundSquare.bounds.extents.z, surroundSquare.bounds.center.z + surroundSquare.bounds.extents.z)); } if (rand % 4 == 2) { troopscript.movDESTINATION = new Vector3(Random.Range(surroundSquare.bounds.center.x - surroundSquare.bounds.extents.x, surroundSquare.bounds.center.x + surroundSquare.bounds.extents.x), hitDUDE.point.y, surroundSquare.bounds.center.z + surroundSquare.bounds.extents.z); } if (rand % 4 == 3) { troopscript.movDESTINATION = new Vector3(surroundSquare.bounds.center.x + surroundSquare.bounds.extents.x, hitDUDE.point.y, Random.Range(surroundSquare.bounds.center.z - surroundSquare.bounds.extents.z, surroundSquare.bounds.center.z + surroundSquare.bounds.extents.z)); } } else { troopscript.target = null; troopscript.movDESTINATION = new Vector3(hitDUDE.point.x - troopscript.offsetX, hitDUDE.point.y, hitDUDE.point.z - troopscript.offsetZ); } if (SelectedTroops.ChangelingsNB >= 1) { CHworking.Play(); } if (SelectedTroops.PAANB >= 1) { PAAworking.Play(); } troopscript.startmovin(); endDrop :; } } }
public void Arrange() { troops = GameObject.FindGameObjectsWithTag("troopsel"); if (dirty && avatars != null) { for (int i = 1; i <= avatars.Length - 1; i++) { Destroy(avatars [i]); } } more.text = ""; if (troops.Length == 1) //Only one troop => details { Instantiate(TroopAvatar, new Vector3(gameObject.transform.position.x + ((float)Screen.width / 840) * (distance + offsetX), gameObject.transform.position.y - ((float)Screen.height / 473) * offsetY, gameObject.transform.position.z), Quaternion.identity); avatars = GameObject.FindGameObjectsWithTag("avatar"); avatars [avatars.Length - 1].transform.SetParent(overlord.transform.parent); avatars [avatars.Length - 1].transform.localScale = new Vector3(1, 1, 1); buttonscript = avatars [avatars.Length - 1].GetComponentInChildren <TroopButton> (); buttonscript.order = 0; objscript = troops [troops.Length - 1].GetComponent <ChangelingTroop> (); if (objscript.specie == 1) { objscript.FoodCountGUI = avatars [avatars.Length - 1].transform.GetChild(2).gameObject.GetComponentInChildren <Text> (); avatars [avatars.Length - 1].transform.GetChild(2).gameObject.GetComponentInChildren <Text> ().text = objscript.food + ""; avatars [avatars.Length - 1].transform.GetChild(2).gameObject.GetComponentInChildren <Image> ().transform.localScale = new Vector2(0.08f, 0.08f); } if (objscript.tip == "Villager") { buttonscript.gameObject.GetComponent <Button> ().spriteState = Changeling; buttonscript.gameObject.GetComponent <Image> ().sprite = Changeling.disabledSprite; goto nexte; } if (objscript.tip == "Ponies-At-Arms") { buttonscript.gameObject.GetComponent <Button> ().spriteState = PoniesAtArms; buttonscript.gameObject.GetComponent <Image> ().sprite = PoniesAtArms.disabledSprite; goto nexte; } nexte: objscript.GUILbar = avatars [avatars.Length - 1].GetComponentInChildren <LifeBar> (); objscript.GUILbar.reflectlief = troops [troops.Length - 1].GetComponent <ChangelingTroop> (); lifecounttext = avatars [avatars.Length - 1].GetComponentInChildren <GUIlifeCount> (); troopname = avatars [avatars.Length - 1].transform.GetChild(1).GetComponent <Text> (); troopname.transform.SetParent(avatars [avatars.Length - 1].transform.GetChild(0).transform.parent); lifecounttext.transform.SetParent(avatars [avatars.Length - 1].transform.GetChild(0).transform.parent); lifecounttext.lifeorigin = troops [troops.Length - 1].GetComponentInChildren <LifeBar> (); lifecounttext.begin(); troopname.text = objscript.tip; } else { if (troops.Length > 27) { for (int ind = 0; ind <= 8; ind++) { Spawn(ind, 0); } for (int ind = 9; ind <= 17; ind++) { Spawn(ind, 30); } for (int ind = 18; ind <= 25; ind++) { Spawn(ind, 60); } if (troops.Length == 27) { Spawn(26, 60); } else { more.text = "+" + (troops.Length - 26) + '\n' + "More"; moreobject.transform.position = new Vector3(gameObject.transform.position.x + ((float)Screen.width / 840) * (distance + (26 % 9) * distance), gameObject.transform.position.y - ((float)Screen.height / 473) * 60, gameObject.transform.position.z); moreobject.transform.SetParent(overlord.transform.parent); } goto ende; } else if (troops.Length >= 19) { for (int ind = 0; ind <= 8; ind++) { Spawn(ind, 0); } for (int ind = 9; ind <= 17; ind++) { Spawn(ind, 30); } for (int ind = 18; ind <= troops.Length - 1; ind++) { Spawn(ind, 60); } goto ende; } if (troops.Length >= 10) { for (int ind = 0; ind <= 8; ind++) { Spawn(ind, 0); } for (int ind = 9; ind <= troops.Length - 1; ind++) { Spawn(ind, 30); } goto ende; } for (int ind = 0; ind <= troops.Length - 1; ind++) //only one Row { Spawn(ind, 0); } } ende :; dirty = true; }