- Home /
Why transform class list give me error?
Hi! I have a public class with two transforms, and I made them a list. The problem is when I fill up the first list, I can't fill up the second one becuse it's gives back null.
public class MovePoints : Transform
{
public Transform OnePoint { get; set; }
public Transform TwoPoint { get; set; }
}
public List <MovePoints> list;
for (int i = 0; i < 6; i++)
{
list.Add(new MovePoints { OnePoint = Something.GetComponent<ArrayOne>().array[i].transform });
}
for (int i = 0; i < 6; i++)
{
list.Add(new MovePoints { CowPoint = Something.GetComponent<ArrayTwo>().array[i].transform });
}
What I realized after a bit, is when I set the secon "for" index to 6 then, it gives values to the "TwoPoint" transform too. So it's only one list, and I though it is two list about the two transform.
So the real Question how can I assign both of them to a list?
Answer by Llama_w_2Ls · Nov 27, 2020 at 06:14 PM
This code:
for (int i = 0; i < 6; i++)
{
list.Add(new MovePoints { OnePoint = Something.GetComponent<ArrayOne>().array[i].transform });
}
for (int i = 0; i < 6; i++)
{
list.Add(new MovePoints { CowPoint = Something.GetComponent<ArrayTwo>().array[i].transform });
}
Isn't in a class, neither is it in a function. Was this intentional or is this a typo/issue with your upload?
Also you can't have two for() loops in a row like that with the same parameters. It has to be: for(int i = 0...)
and for (int j = 0...)
to be two separate for loops. @gellihorvath
Your answer
Follow this Question
Related Questions
2d Circle won't change size 0 Answers
Argument Out of Range when accessing List 2 Answers
Calling GameObject's transform from list 1 Answer
How can I make a list of Classes or Scripts? 3 Answers
using classes in List<>'s 1 Answer