unity3d c# 的代码错误

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'
傻傻的俪 1年前 已收到1个回答 举报

田宝贝 种子

共回答了16个问题采纳率:81.3% 举报

openWith1 的key是int型的,
openWith0[0][i] 得到的是字符串

1年前

1
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.024 s. - webmaster@yulucn.com