Terrain ter = (Terrain)terrain.GetComponent(typeof(Terrain));
TerrainData ter = ter.terrainData;
Type ter = ...
says that a new variable of type
Type (here Terrain or TerrainData) has to be created. But at
TerrainData ter = ...
, there already exists a variable of type
ter in the same (or the outer) scope, so it can't do that.
Give the second 'ter' a different name:
TerrainData data = ter.terrainData;
for example. Then use the
data
variable wherever you need it.
You speak of getting "more errors" when you tried another name; if the above step is what you tried but it gives errors, then read the errors (maybe do a Google search if necessary) and figure out what's wrong with the code.