Unity gets the size of Terrain

Unity gets the size of Terrain

For Unity's strategy games, it is possible to limit the movement of the camera according to the size of the scene. How to obtain the size of the terrain?
The size can be obtained from the terrainData property of the Terrain object, see the code for details:

            GameObject terrainObj = GameObject.FindGameObjectWithTag("Terrain");
            if(terrainObj != null)
            {
                Terrain terrain = terrainObj.GetComponent<Terrain>();
                this.terrainSize = Mathf.Max(terrain.terrainData.size.x, terrain.terrainData.size.z);
            }

Guess you like

Origin blog.csdn.net/zhush_2005/article/details/107078925