public void MoveChildren() { bool shouldDestroy = false; for (int c = transform.childCount - 1; c >= 0; c--) { Transform child = transform.GetChild(c); HexChunk chunk = child.GetComponent <HexChunk>(); if (chunk != null) { chunk.MoveChildren(); } else { Hexagon hex = child.GetComponent <Hexagon>(); hex.gameObject.SetActive(true); Vector3 hexPos = hex.transform.position; HexGrid grid = GameObject.FindWithTag("Hexgrid").GetComponent <HexGrid>(); hexPos.y = grid.GetYPos(hex.xValue, hex.zValue); hex.SetPositions(hexPos); hex.transform.parent = transform.parent; shouldDestroy = true; } } if (shouldDestroy) { Destroy(gameObject); } }
IEnumerator ChangeHeightMap(string name) { heightMap = Resources.Load <Texture2D>("Images/" + name); foreach (GameObject obj in chunks) { HexChunk hc = obj.GetComponent <HexChunk>(); hc.MoveChildren(); StartCoroutine("ReCombine", hc.gameObject); yield return(null); } }
void ShootTerraformer(string objectHit, Vector3 point, float charge, int dir) { bool hasHit = false; float chargedRadius = radius * (Mathf.Floor(/*Mathf.Clamp(*/ charge /*, 1, maxChargeTime)*/) + 1); Collider[] objectsHit = Physics.OverlapSphere(point, chargedRadius); for (int n = 0; n < objectsHit.Length; n++) { HexChunk hexChunk = objectsHit [n].GetComponent <HexChunk>(); if (hexChunk != null) { //Resettime x 2 uit hexagon prefab hexChunk.StopAllCoroutines(); hexChunk.StartCoroutine("SplitChunk", 20); hexChunk.MoveChildren(point, chargedRadius, dir); hasHit = true; continue; } Hexagon hex = objectsHit [n].GetComponent <Hexagon>(); if (hex != null) { hex.MoveHexagon(point, chargedRadius, dir); hasHit = true; continue; } if (dir == 1) { if (objectsHit [n].tag == "Player") { Vector3 launchDir = Vector3.Normalize(objectsHit [n].transform.position - point); launchDir.y = 1; objectsHit [n].GetComponent <Player_Force>().AddImpact(launchDir, (50 / objectsHit [n].transform.localScale.x) * chargedRadius); } else if (objectsHit [n].tag == "PhysicsObject" || objectsHit [n].tag == "Flag" || objectsHit [n].tag == "Ball") { /*float force = 0; * switch ((int)chargedRadius) * { * case 3: * { * force = 4000; * break; * } * case 6: * { * force = 6000; * break; * } * case 9: * { * force = 8000; * break; * } * }*/ objectsHit [n].GetComponent <Rigidbody>().AddForce(Vector3.up * (1500 + 2000 * (chargedRadius / 3)) /*force*/); if (objectsHit [n].tag == "Ball") { objectsHit [n].GetComponent <GM_Ball>().lastHitBy = transform.name; } } } } if (hasHit) { StartCoroutine(ShootTimer(reloadTime)); StartCoroutine(PlayRubbleSound()); } }