- Home /
Script Error
I have this script which I think is supposed to set the height of my terrain so I can lower it but when I click on the option which is called raise or lower terrain I get an error saying "method not found UnityEngine.Object.GetComponent". Can anyone help me out with this?
class RaiseHeightmap extends ScriptableWizard {
var addHeight = .1;
static var terrain : TerrainData;
@MenuItem ("Terrain/Raise or Lower Heightmap...")
static function CreateWizard () {
terrain = null;
var terrainObject : Terrain = Selection.activeObject.GetComponent(Terrain) as Terrain;
if (!terrainObject) {
terrainObject = Terrain.activeTerrain;
}
if (terrainObject) {
terrain = terrainObject.terrainData;
var buttonText = "Apply Height";
}
else {
buttonText = "Cancel";
}
ScriptableWizard.DisplayWizard("Raise/Lower Heightmap", RaiseHeightmap, buttonText);
}
function OnWizardUpdate () {
if (!terrain) {
helpString = "No terrain found";
return;
}
addHeight = Mathf.Clamp(addHeight, -1.0, 1.0);
helpString = (terrain.size.y*addHeight) + " meters (" + parseInt(addHeight*100.0) + "%)";
}
function OnWizardCreate () {
if (!terrain) {
return;
}
Undo.RegisterUndo(terrain, "Raise or Lower Heightmap");
var heights = terrain.GetHeights(0, 0, terrain.heightmapWidth, terrain.heightmapHeight);
for (y = 0; y < terrain.heightmapHeight; y++) {
for (x = 0; x < terrain.heightmapWidth; x++) {
heights[y,x] = heights[y,x] + addHeight;
}
}
terrain.SetHeights(0, 0, heights);
terrain = null;
}
}
Comment
Best Answer
Answer by nschrag · Mar 29, 2012 at 07:09 PM
GetComponent is a member of GameObject, and Selection.activeObject is simply an Object. You'll need to cast Selection.activeObject.
Related documentation:
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Terrain Code 1 Answer
Object2Terrain error/wont work. 1 Answer
A node in a childnode? 1 Answer
Spawning Error.. 0 Answers