- Home /
The question is answered, right answer was accepted
How do I combine two arrays of a common parent class?
I have created scripts containing "Discrete" and "Continous" classes which extends
from "Movement" class. I use the following code to retreive components individually from a parent node:
var dis : Movement[] = GetComponentsInChildren (Discrete);
var con : Movement[] = GetComponentsInChildren (Continous);
How do I combine them into a var allMovements : Movement[]
?
I tried allMovements = dis.Concat(con);
but the console says that Concat can't be used here. Any suggestion?
http://answers.unity3d.com/questions/59153/how-to-combine-vector3-arrays.html
You will have to change the code from Vector3 to $$anonymous$$ovement.
Answer by whydoidoit · Feb 20, 2014 at 07:19 AM
If they are derived from Movement then all you need is:
allMovements = GetComponentsInChildren(Movement);
If you really want to combine them:
import System.Linq;
all$$anonymous$$ovements = GetComponentsInChildren(Discrete).Cast.<$$anonymous$$ovement>().Concat(GetComponentsInChildren(Continous)).ToArray();
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Array empties values on RunTime? 1 Answer
For loop not running correctly inside start () 1 Answer
transform array in javascript 2 Answers
Add a copy of a object to Array 1 Answer