public void AfterSpawning() { if (terrain == null) { return; } //Rotate terrain back terrain.transform.rotation = Quaternion.Euler(0, 0, 0); //generate a new rotated one Vector3 elementRotation = OrigianlTerrainCorner.transform.rotation.eulerAngles; Debug.Log("element rotation: " + elementRotation); float angle = 360 - elementRotation.y; Debug.Log("rotating degree: " + angle); RuntimeTerrainRotator rttr = new RuntimeTerrainRotator(); GameObject nGo = new GameObject(); nGo.layer = terrain.layer; nGo.transform.parent = terrain.transform.parent; nGo.name = "Generated Terrain"; rttr.RotateTerrain(terrain, nGo, angle, terrainDataDuplicate); //reset position of terrain Vector3 newCornerToCenter = Quaternion.Euler(0, elementRotation.y, 0) * CornerToCenter; //GameObject n = new GameObject(); n.transform.position = OrigianlTerrainCorner.transform.position + CornerToCenter; n.name = "Original Corner + Corner To Center"; //GameObject nn = new GameObject(); nn.transform.position = OrigianlTerrainCorner.transform.position + newCornerToCenter; nn.name = "Original Corner + new To Center"; //GameObject nnn = new GameObject(); nnn.transform.position = terrainCenter.transform.position + CornerToCenter; nnn.name = "Center + Corner To Center"; //GameObject nnnn = new GameObject(); nnnn.transform.position = terrainCenter.transform.position + newCornerToCenter; nnnn.name = "Center + new CornerToCenter"; nGo.transform.position = OrigianlTerrainCorner.transform.position + newCornerToCenter + -CornerToCenter; }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.R)) { Debug.Log("Presed R"); GameObject t = FindObjectOfType <Terrain>().gameObject; RuntimeTerrainRotator rttr = new RuntimeTerrainRotator(); GameObject nGo = new GameObject(); rttr.RotateTerrain(t, nGo, 45, terrainDataDuplicate); } }