简体   繁体   中英

Unity3d out of range error on a list when defining variables out of each element

I have a list with which I want to define three variables out of it.

YearText.text=CarInfoList[0].CarYear;
MakeText.text=CarInfoList[1].CarMake;
ModelText.text=CarInfoList[2].CarModel;

The list has one record set with the variable elements defined in a constructor script. The first line works just fine and displays as expected, but when I try the second or third, it give me an out of range error. Anyone have some thoughts? Thanks!

you said right in your question that there is only one record set...

you want this...

YearText.text=CarInfoList[0].CarYear;
MakeText.text=CarInfoList[0].CarMake;
ModelText.text=CarInfoList[0].CarModel;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM