unity3d c# 的代码错误Dictionary openWith0 = new Dictionary();//定义字典Dictionary openWith1 = new Dictionary();//定义字典openWith0.Add(0, "0,500,1000,1500,2000,3500,4500,6500,7500,8500,10000,14000,15000,16000,18000,19000,21000".Spli

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 06:17:43
unity3d c# 的代码错误Dictionary  openWith0 = new Dictionary();//定义字典Dictionary  openWith1 = new Dictionary();//定义字典openWith0.Add(0,

unity3d c# 的代码错误Dictionary openWith0 = new Dictionary();//定义字典Dictionary openWith1 = new Dictionary();//定义字典openWith0.Add(0, "0,500,1000,1500,2000,3500,4500,6500,7500,8500,10000,14000,15000,16000,18000,19000,21000".Spli
unity3d c# 的代码错误
Dictionary openWith0 = new Dictionary();//定义字典
Dictionary openWith1 = new Dictionary();//定义字典
openWith0.Add(0, "0,500,1000,1500,2000,3500,4500,6500,7500,8500,10000,14000,15000,16000,18000,19000,21000".Split(','));
openWith1.Add(0, "1,2,3".Split(','));
for (int i = 0;i < openWith0[0].Length;i++)
{
for (int j = 0;j < openWith1[openWith0[0][i]].Length;j++)//就是这行报错
{
if (j == 0)
{
Instantiate(m1,new Vector3 (Random.Range(200,300), Random.Range(-800,-700),0),transform.rotation);
}
}
}
报错:
Assets/script/gamelogic.cs(55,44): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary.this[int]' has some invalid arguments
Assets/script/gamelogic.cs(55,44): error CS1503: Argument `#1' cannot convert `string' expression to type `int'

unity3d c# 的代码错误Dictionary openWith0 = new Dictionary();//定义字典Dictionary openWith1 = new Dictionary();//定义字典openWith0.Add(0, "0,500,1000,1500,2000,3500,4500,6500,7500,8500,10000,14000,15000,16000,18000,19000,21000".Spli
openWith1 的key是int型的,
openWith0[0][i] 得到的是字符串