- Home /
Remove first element of array
First a question. If I say:
Transform[] nodes = test.GetComponentsInChildren<Transform>();
Will it always take the test (which is the parent) as the first element in the array?
And if it does, how do I either start array from element number 2, or delete element number 1?
nodes = test.GetComponentsInChildren<Transform>();
nodes [0] = nodes [nodes.Length - 1];
@$$anonymous$$r$$anonymous$$eloPie - your comment may be a great answer for your particular situation, it does not directly answer your question. Your first entry and your last entry now share the same value...and since your nodes are Transforms, these value are by reference. So if you walk your array and perform some operation, the first node will have that operation performed twice.
Answer by KennethFE · Oct 27, 2014 at 04:32 AM
If you use an List Object instead a array ?
List< Transform > nodesAux = new List< Transform >();
foreach (Transform trans in test.GetComponentsInChildren< Transform >())
{
nodesAux.Add ( trans.gameObject );
}
int c = nodesAux.Count;
list.RemoveAt(c);
Your answer
Follow this Question
Related Questions
Find closest object with tag 1 Answer
Find children of object and store in an array 3 Answers
Find closest transform 1 Answer
Closest array element 1 Answer
Particle System Delay 0 Answers