在以统一方式上传代码时,我遇到了错误 [英] While uploading code in unity I am getting below error

查看:153
本文介绍了在以统一方式上传代码时,我遇到了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误CS0136:无法在此范围内声明名为ter的局部变量,因为它会给ter赋予不同的含义,ter已在子范围内用于表示其他内容



案例2:

地形ter =(地形)terrain.GetComponent(typeof(Terrain));

if(ter = = null){

返回;

}

TerrainData ter = ter.terrainData;

terrain.splatPrototypes = terData.splatPrototypes;

EditorGUILayout.Separator();

float mouseX;

EditorGUILayout.BeginHorizo​​ntal();

GUI.skin = terrain.guiSkin;

GUILayout.Label(纹理坡度);



我试过的:



i在我收到更多错误后尝试将tre更改为其他名称。

error CS0136: A local variable named `ter' cannot be declared in this scope because it would give a different meaning to `ter', which is already used in a `child' scope to denote something else

case 2:
Terrain ter = (Terrain) terrain.GetComponent(typeof(Terrain));
if (ter == null) {
return;
}
TerrainData ter = ter.terrainData;
terrain.splatPrototypes = terData.splatPrototypes;
EditorGUILayout.Separator();
float mouseX;
EditorGUILayout.BeginHorizontal();
GUI.skin = terrain.guiSkin;
GUILayout.Label("Texture Slope");

What I have tried:

i try to change tre to some other name after i am getting more errors.

推荐答案

ter 变量已使用其他类型声明。它看起来像这一行中的拼写错误:

The ter variable has been already declared with a different type. It looks like a typo in this line:
TerrainData ter = ter.terrainData;

应该是

It should be

TerrainData terData = ter.terrainData;

因为之后你正在使用 terData 变量。

because you are using a terData variable afterwards.


Terrain ter = (Terrain)terrain.GetComponent(typeof(Terrain));

TerrainData ter = ter.terrainData;



类型 ter = ... 表示新变量必须创建类型(此处为Terrain或TerrainData)类型。但是在 TerrainData ter = ... 中,在相同(或外部)范围内已存在 ter 类型的变量,因此它可以这样做。



给第二个'ter'一个不同的名字: TerrainData data = ter.terrainData; 例如。然后在任何需要的地方使用数据变量。



您说的是在尝试时遇到更多错误另一个名字;如果上面的步骤是您尝试过的但它会出错,那么请阅读错误(如果需要,可以进行Google搜索)并找出代码有什么问题。


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.


这篇关于在以统一方式上传代码时,我遇到了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆