x


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

more ▼

asked Jun 20 '10 at 12:37 AM

redcap gravatar image

redcap
12 2 2 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Add below the var go line in your script:

var terrain : Terrain = go.GetComponent(Terrain);
var 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

more ▼

answered Jun 20 '10 at 12:45 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

(comments are locked)
10|3000 characters needed characters left

The general way of finding the "size" of an object is to get the renderer.bounds

more ▼

answered Jun 20 '10 at 12:51 AM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

Not going to work for terrain though, it doesn't inherit Renderer

Jun 20 '10 at 12:56 AM Mike 3
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1467
x318
x20
x12

asked: Jun 20 '10 at 12:37 AM

Seen: 3487 times

Last Updated: Jun 20 '10 at 01:34 AM