unity define array
int[] arr1 = new int[3];
// Create an integer array with 3 elements
var arr2 = new int[3];
// Same thing, just with implicit declaration
var arr3 = new int[] { 1, 2, 3 };
// Creates an array with 3 elements and sets values.
4
1
// Modified version of: https://answers.unity.com/questions/873650/how-to-make-a-list-or-array-of-functions-with-type.html
// Modified By Malte0621
delegate void FuncsMethod();
void CreateList()
{
List<FuncsMethod> funcs = new List<FuncsMethod>();
// Add Functions ...
funcs.Add(function1);
funcs.Add(function2);
// Call Function ...
funcs[0]();
}
// Functions
void function1()
{
Debug.Log("Function 1 called.");
}
void function2()
{
Debug.Log("Function 2 called.");
}
Thank you!
1
0
4
11
public string[] myArrayName = new string[4];
Thank you!
11
0
0
1
string[ ] familyMembers = new string[]{"John", "Amanda", "Chris", "Amber"} ;
string[ ] carsInTheGarage = new string[] {"VWPassat", "BMW"} ;
int[ ] doorNumbersOnMyStreet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
GameObject[ ] carsInTheScene = GameObject.FindGameObjectsWithTag("car");
Thank you!
1
0
3
2
//creates an array of arrays int[][] myarray; //creates an array which contains 20 arrays the arrays are all empty and unitialized, they will need to be initialized, there is currently just 20 starting points reserved in memory. They point to nothing really. myarrays = new int[20][]; //the first array is size 3 with the element 0 & 1 & 1 myarrays[0] = {0,1,1}; myarrays[0][0] = ? //based on the statement above it equals 0 myarrays[0][1] = ? //based on the statement above it equals 1 myarrays[0][2] = ? //based on the statement above it equals 1 as well //the following code will take every array in myarrays and make them equal to arrays of size 10, the arrays are empty but now they point to something, its probably zero by default due to internal code. for (int x = 0; x <= myarrays.size(); x++) { myarrays[x] = new int[10]; } //technically the code above still hasnt set what the value of each element in the arrays are, it simply now says its size is definitely 10, internally the code has probably set those memory values to zero however to help prevent unexpected errors, that's not guaranteed I don't think however and it would probably be best to set each value to be certain different machines and things dont do things differently and create unexpected and hard to find errors. //the follow code will create an array that contains 20 arrays, each of those arrays are of size 10, and each of them will have the value set to 0; int[][] myarrays = new int[20][]; //careful on this for statement, it is less than not less than or equal too, this has to do with size starting to count from 1 and x starting to count from 0. You must start from 0 because the first index in an array is 0. for(int x = 0; x < myarrays.size(); x++) { myarrays[x] = new int[10]; for (int y = 0; y < myarrays[x].size(); y++) { myarrays[x][y] = 0; } } //Do note that i used the size function to get the size, thats because you shouldn't used numbers like 20 or 10 even if thats what you think you want. You should declare a constant called NUMBER_OF_ARRAYS and NUMBER_OF_ELEMENTS_IN_ARRAYS or something like that and substitute those that way you can change the size of the arrays with a few keyboard strokes.
Thank you!
2
0
4.5
8
using System.Collections.Generic;
Thank you!
8
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line