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
반응형
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
How do I make member structs accessible in the editor? (0) | 2018.10.08 |
---|---|
Physics.BoxCastAll (0) | 2018.10.08 |
Can Rigidbody 2D collide with 3D Colliders? (2D, 3D Collision) (0) | 2018.08.04 |
Box Collider 2D -failed verification- warning even when the size is reasonable (0) | 2018.08.04 |
PlayerPrefs (0) | 2018.07.15 |