- Home /
Problem is not reproducible or outdated
Why is function "SampleHeight" not available
Hi!
I try to get a specific height at the given position defined in world space, relative to the terrain space. I use function " transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position);" but it prints errors "error CS0176: Static member `UnityEngine.Terrain.activeTerrain' cannot be accessed with an instance reference, qualify it with a type name instead". The script is attached with one object.
It's something with the use of Terrain.activeTerrain. If, for example, you create a variable
public Terrain terrain;
and assign the terrain in the Inspector to that variable, then do
terrain.SampleHeight...
that works
I just did the following, and it compiled fine for me:
function Start() {
transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position);
}
Follow this Question
Related Questions
Problem with Terrain.SampleHeight 0 Answers
Detect closest reachable point of object 1 Answer
Incorrect height with sampleHeight 1 Answer
Make a simple tree 1 Answer
Making the player be sticked to the ground, help please! 1 Answer