-2

First I create the Vector3:

Vector3[] foo = {
    1, 2, 3
}

Later in my code, I need to add a new item to foo, but I can't find a way to do this.

I have tried foo.Add(4), but I get the error: Vector3 does not contain a definition for Add

I want foo to end up as 1, 2, 3, 4

Kit
  • 89
  • 1
  • 6

1 Answers1

0

Use a list instead of an Array. It will give you more options to add and remove items.

List<Vector3> yourList = new List<Vector3>() { 1,2,3};
yourList.Add(4); // Add a new element
yourList.Add(5); // Add a new element
yourList.Remove(5); // Remove an element.

Let me know if it helps.

  • Is there a way to convert the List into a Vector3 Array? I need to use it as the vertices for a mesh. – Kit May 05 '19 at 17:51