This is for javascript. Pretty simple question. I want an array to store a series of vectors, but I don’t know the syntax for creating and adding new vectors to the array. Thanks.
There are two types of arrays(there are more but lets focus on these two), the first is a native .NET array. The main differences are that it is static, meaning that the length has to be preset. In order to change the length it has to be remade. Another difference is that the built-in .NET arrays can be edited and set in the inspector. While remaking can be a pain for the CPU, if you arent going to remake them often or at all then they are the one to pick since they are faster.
var values : float[];
function Start () {
// Since we can't resize builtin arrays
// we have to recreate the array to resize it
values = new float[10];
// assign the second element(they start at 0)
values[1] = 5.0;
}
The second is a class. These are dynamic, meaning that they can be re sized at any time without remaking them. If you are going to resized them a TON this is the way to go since while they are much slower, you don’t have to remake them(slower).
var vectors = new Array();
function Start(){
vectors.Push(Vector3(0,0,0)); /// Add a entry, it will resize it to one and assign it.
/// Manual or backend way(What is happening in the above line)
vectors.length(2); ///Size up by one
vectors[1] = Vector3(0,1,0); /// Assign second slot
}