게임엔진(GameEngine)/Unity3D
How to get a List<> from GetComponents?
3DMP
2018. 10. 7. 12:04
How to get a List<> from GetComponents?
GetComponents returns a []. Is there any one-liner way to convert that to a Generic (List or whatever)?
With LINQ (requires using System.Linq;
):
var list = GetComponents<SomeComponent>().ToList();
Without LINQ:
var list = new List<SomeComponent>(GetComponents<SomeComponent>());
Code in C#.
ref : https://answers.unity.com/questions/630680/how-to-get-a-list-from-getcomponents.html
반응형