In Script One I create a “Big List” of 15 items, each item contains three Integers – at present, it’s merely meaningless test data.
In Script Two, I print the entire list, 15 items, three integers each – no problem, the list picks up the data and prints it perfectly…random numbers or assigned numbers, I have no problem at all extracting the full list and printing it accurately.
In Script Three I create a “Small List” of three items selected from the “Big List” in Script One and I get the message “ArgumentOutOfRangeException: Argument is out of range. Parameter name: index”
Here is script one:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptOne : MonoBehaviour
{
public List<NumTestClass> bigList = new List<NumTestClass> ();
void Start()
{
for (int i = 0; i < 15; i++)
{
int num01 = 11;
int num02 = 22;
int num03 = 33;
bigList.Add (new NumTestClass (num01, num02, num03));
}
}
}
public class NumTestClass
{
public int numberOne {get; set;}
public int numberTwo {get; set;}
public int numberThree {get; set;}
public NumTestClass (int one, int two, int three)
{
numberOne = one;
numberTwo = two;
numberThree = three;
}
}
Here is script two: ///////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class ScriptTwo : MonoBehaviour
{
void OnGUI()
{
for (int i = 0; i < 15; i++)
{
string tempString01 = GetComponent<ScriptOne> ().bigList *.numberOne.ToString("F1");;*
_ string tempString02 = GetComponent ().bigList .numberTwo.ToString(“F1”);_
_ string tempString03 = GetComponent ().bigList .numberThree.ToString(“F1”);_
_ GUI.Label (new Rect (25, i * 25 + 100, 150, 20), tempString01 + " - " + tempString02 + " - " + tempString03);
* }
}
}*_
Here is script three //////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptThree : ScriptOne
{
* public List smallList = new List ();*
* void Start ()*
* {*
* int counter = 0;*
* while (counter < 3)*
* {*
* int temp01 = GetComponent().bigList[counter].numberOne;*
* int temp02 = GetComponent().bigList[counter].numberTwo;*
* int temp03 = GetComponent().bigList[counter].numberThree;*
* smallList.Add(new RaceTestClass (temp01, temp02, temp03));*
* counter++;*
* }*
* }*
}
public class RaceTestClass
{
* public int thingOne { get; set;}*
* public int thingTwo {get; set;}*
* public int thingThree {get; set;}*
* public RaceTestClass (int one, int two, int three)*
* {*
* thingOne = one;*
* thingTwo = two;*
* thingThree = three;*
* }*
}