- Home /
The question is answered, right answer was accepted
Get the dimensions of a terrain
Sorry if this question is so silly, but I really have looked hard for an answer and can't find one.
I am trying to make a particle system that has the same x width and z lenght of my terrain, and so what I thought to do was through code get those dimensions and then through code change my particle systems range in the x and z direction to match the terrain's dimensions.
So I set my landscape as a variable in the following way
function Start ()
{
var go = GameObject.Find("landscape");
}
but can't find out how to access the dimensions. Is there a way? Also is my approach even a logical one, or is there an easier way. Thank you so much
Answer by Mike 3 · Jun 20, 2010 at 12:45 AM
Add below the var go line in your script:
var terrainSize : Vector3;
function Start ()
{
var go = GameObject.Find("landscape");
var terrain : Terrain = go.GetComponent(Terrain);
terrainSize = terrain.terrainData.size;
}
That'll give you a vector3 in world units
Documented here: http://unity3d.com/support/documentation/ScriptReference/TerrainData-size.html http://unity3d.com/support/documentation/ScriptReference/TerrainData.html http://unity3d.com/support/documentation/ScriptReference/Terrain.html
Answer by Tetrad · Jun 20, 2010 at 12:51 AM
The general way of finding the "size" of an object is to get the renderer.bounds
Not going to work for terrain though, it doesn't inherit Renderer
TerrainData has bounds https://docs.unity3d.com/ScriptReference/TerrainData-bounds.html
Follow this Question
Related Questions
Using shuriken to create volumetric lights effect 5 Answers
Make a simple tree 1 Answer
What should I dimension my terrain? 0 Answers
Technique for volumetric grass. Texturing question. 1 Answer