private void SetStartRegion(unitStruct tempUnit, GameObject unitObject) { float rad = Mathf.Sqrt((Mathf.Pow(unitObject.transform.localScale.x, 2) + Mathf.Pow(unitObject.transform.localScale.y, 2))); Collider[] coll = Physics.OverlapSphere(new Vector3(unitObject.transform.position.x, unitObject.transform.position.y, -0.5f), rad); GameObject region = null; foreach (var item in coll) { if (item.gameObject == unitObject ) { continue; } //Debug.Log(item.transform.parent.ToString()); region = (item.transform.parent).gameObject; } if (region != null) { tempUnit.position = GameObject.Find("Gamelogic").GetComponent<GameInfo>().GetSelectedRegion(region.name); } }
void InitUnitStructs() { int ID = 0; foreach (var item in mPlayerList) { for (int i = 0; i < 5; i++) { unitStruct u = new unitStruct(); unitStruct tempUnit = u.CreateSoldier(item.PlayerHouse); ID++; tempUnit.ID = ID; mUnitsStructList.Add(tempUnit); GameObject n = (GameObject)Instantiate(UnitPrefab, new Vector3(ID, ID, 0), Quaternion.identity); n.name = "UNIT_" + ID.ToString(); n.transform.parent = UnitContainer.transform; SetStartRegion(tempUnit, n); } for (int i = 0; i < 3; i++) { unitStruct u = new unitStruct(); unitStruct tempUnit = u.CreateKnight(item.PlayerHouse); ID++; tempUnit.ID = ID; mUnitsStructList.Add(tempUnit); GameObject n = (GameObject)Instantiate(UnitPrefab, new Vector3(ID, ID, ID), Quaternion.identity); n.name = "UNIT_" + ID.ToString(); n.transform.parent = UnitContainer.transform; SetStartRegion(tempUnit, n); } for (int i = 0; i < 2; i++) { unitStruct u = new unitStruct(); unitStruct tempUnit = u.CreateMachine(item.PlayerHouse); ID++; tempUnit.ID = ID; mUnitsStructList.Add(tempUnit); GameObject n = (GameObject)Instantiate(UnitPrefab, new Vector3(ID, ID, ID), Quaternion.identity); n.name = "UNIT_" + ID.ToString(); n.transform.parent = UnitContainer.transform; SetStartRegion(tempUnit, n); } for (int i = 0; i < 4; i++) { unitStruct u = new unitStruct(); unitStruct tempUnit = u.CreateShip(item.PlayerHouse); ID++; tempUnit.ID = ID; mUnitsStructList.Add(tempUnit); GameObject n = (GameObject)Instantiate(UnitPrefab, new Vector3(ID, ID, ID), Quaternion.identity); n.name = "UNIT_" + ID.ToString(); n.transform.parent = UnitContainer.transform; SetStartRegion(tempUnit, n); } } }