- Home /
Question by
Kadorath · Oct 19, 2017 at 02:40 AM ·
arrayassignment
How do you assign an array to an array
If I had a function that generated and then returned an array, how could I then give that array to an array outside of the function. Is it possible to just set one array to another, like this?
GameObject[] objArr = generateArr();
public GameObject[] generateArr(){
GameObject[] arr = {*GameObjects*};
}
Comment
Answer by Vanilla-Plus · Oct 19, 2017 at 03:17 AM
As far as I know, you can simply set the array as expected. Eg
OtherObject.secondArray = firstArray;
Even better would be having the function that generates the GameObject array being referenced directly like so;
GameObject[] generateArray() {
GameObject[] newArray = new GameObject[1];
newArray[1] = new GameObject();
return newArray;
}
void Start() {
otherObject.myArray = generateArray();
}
Your answer
Follow this Question
Related Questions
AudioClip.SetData not working 2 Answers
Array copy 2 Answers
Wrong object always Instantiated 1 Answer
Read different game objects into array at same time? 2 Answers
How to make an array list set to false gradually instead of instantly? 2 Answers