Unity - A计划(一年有效期) 扫二维码继续学习 二维码时效为半小时

(61评价)
价格: 2208.00元
黑暗之光中,在程序中读取文本,将物品信息读取到文本中
赵哒哒发起了问答2018-09-06
1
回复
444
浏览

数组越界,

1001,小瓶血药,icon1,Drug,50,0,80,100
1002,大瓶血药,icon2,Drug,100,0,180,200
1003,蓝药,icon3,Drug,0,100,150,180

string icon_name = proArray[2];//這里报数组越界

string text = objectInfoText.text;

string[] strArray = text.Split('\n');

foreach (string str in strArray)

{

string[] proArray = str.Split(',');

ObjectInfo info = new ObjectInfo();

int id = int.Parse(proArray[0]);

string name = proArray[1];

string icon_name = proArray[2];//這里报数组越界

string str_type = proArray[3];

ObjectType type = ObjectType.Drug;

switch (str_type)

{ case "Drug":

type = ObjectType.Drug;

break;

case "Equip":

type = ObjectType.Equip; break;

case "Mat":

type = ObjectType.Mat; break;

}

info.id = id; info.name = name; info.icon_name = icon_name; info.type = type;

if (type==ObjectType.Drug)

{ int hp = int.Parse(proArray[4]);

int mp = int.Parse(proArray[5]);

int price_sell = int.Parse(proArray[6]);

int price_buy = int.Parse(proArray[7]);

info.hp = hp; info.mp = mp; info.price_buy = price_buy; info.price_sell = price_sell; }

objectInfoDic.Add(id,info);

}

}

所有回复
  • siki 2018-09-06

    1001,小瓶血药,icon1,Drug,50,0,80,100
    1002,大瓶血药,icon2,Drug,100,0,180,200
    1003,蓝药,icon3,Drug,0,100,150,180

    你的数据是有问题的,里面有的是英文逗号,有的是中文逗号, 保持逗号的统一,统一使用英文逗号

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!