I have made a class that contains an array of Vector3s and I try to add that array in a list. Nothing I’ve tried to do seems to solve this. I get an error every time that array is out of range. Any ideas?
[System.Serializable]
public class NodeClass
{
public Vector3[] location;
}
public List<NodeClass> allNodes;
parts = GameObject.FindGameObjectsWithTag("Part");
for (int i = 0; i < parts.GetLength(0); i++)
{
GameObject go = parts*;*
Part part = go.GetComponent(); Vector3[] nodes = part.nodeLocation; allNodes = new NodeClass(); for (int x = 0; x < nodes.GetLength(0); x++) { allNodes*.location[x] = nodes[x];* } }
You script does not make much sense :P. At not point you add your nodes to your list, and i am confused as to why you are looping through your list again (inside your node loop) to basically re-put the same value ?
Something like this would work, I guess ?
[System.Serializable]
public class NodeClass
{
public Vector3[] location;
public NodeClass(Vector3[] _locations)
{
location = _locations;
}
}
[...]
void test()
{
List<NodeClass> allNodes = new List<NodeClass>();
GameObject[] parts = GameObject.FindGameObjectsWithTag("Part");
for (int i = 0; i<parts.GetLength(0); i++)
{
GameObject go = parts*;*
Part part = go.GetComponent(); Vector3[] nodes = part.nodeLocation;
allNodes.Add(new NodeClass(nodes)); } } }
public class Part { public Vector3[] nodeLocation; }