GetComponent GetScript (again)

Feb 9, 2010 at 10:21 PM

Hey. ive made a short function to populate an area of terrain with trees.

it works by

Terrain heightField = Engine.GetComponent<Terrain>("LandMass1");

then grabbing the y position by referencing the trees generated x& z positions. this works great.


i have no added physics to the terrain which changed it from a component into a script. which means i can no longer GetComponent and i have to GetScript. which leaves me with the unenviable task of rewriting the GrabHeight Function. or at least as far as i can see.

ive currently worked around this by creating a copy of the terrain and changing the visible property to false and calling the copy LandMass1 and the physics terrain LandMass2, this allows me to pick the height from the non scripted terrain and use the physics from the scripted terrain.

is this ok or am i making a huge mistake?



Feb 9, 2010 at 11:51 PM
Edited Feb 9, 2010 at 11:52 PM

A huge mistake I'm pretty sure ;)

Just write a forwarding function like this in the terrain's script -

public int GrabHeight(...)


    return Component.HeightMap.GrabHeight(...);


Remember that scripts are sort of a way of extending existing components, albeit with a more specialized interface.

Let me know if this doesn't make sense for some reason.


Feb 10, 2010 at 12:50 AM

how simple. :D thanks mate!