K
K
kitmen2019-03-18 21:00:57
C++ / C#
kitmen, 2019-03-18 21:00:57

How to put everything in the Physics2D.OverlapCircleAll into an array of the GameObject type?

Can you please tell me whether it is possible to assign an array to the GameObject type, everything that is included in the Physics2D.OverlapCircleAll colo.
Like this, but not Collider2D[] but GameObject[]:
Collider2D[] hh = Physics2D.OverlapCircleAll(transform.position, 12f);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2019-03-18
@kitmen

If I understand you correctly (fortunately I know Ukrainian), then you want to get GameObject[] from Collider[] .
You can use LINQ for this, however I don't recommend using this in Hot code

using System.Linq;

----------

GameObject[] hh = Physics2D.OverlapCircleAll(transform.position, 12f).Select(a => a.GetComponent<GameObject>());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question