- Home /
How to create a LIST of hit.colliders? C#
I want to keep my hit.colliders in one big List<>, and I tried doing following but won't work..
public List<RaycastHit> selected = new List<RaycastHit>();
Also, I'd need to do some looping through, it, and again, following code wouldn't work:
for (int i = 0; i < selected.Count; i++)
selected[i].GetComponent<XXX>().xxxx = xxxx;
Thanks!
To be even more clear, this is what I'm trying to accomplish with LIST..
selected.Add(hit.collider);
Check out http://forum.unity3d.com/threads/103849-Getting-all-applied-collisions-on-an-object. Also, you might want to look into Contact Point
Answer by iwaldrop · Jan 23, 2013 at 10:09 PM
You need a list of RaycastHit.
List<RaycastHit> hits = new List<RaycastHit>();
Oh...ha...my bad. You need a list of Type Collider!
List<Collider> colliders = new List<Collider>();
Wow...I can't read sometime.
Hey, iwaldrop, thanks! Could you help me out even more? Like, how to translate this code from javaunity to C#, using the list you mentioned ins$$anonymous$$d of an array:
for (int i = 0; i < selected.Count; i++) selected[i].GetComponent().xxxx = xxxx;
foreach (Object o in objects)
{
// do something
}
or
objects.ForEach(o => DoSomething(o))
Also, GetComponent works as such in c#:
$$anonymous$$eshRenderer meshRenderer = GetComponent<$$anonymous$$eshRenderer>();
Got it, thank you! :D BTW, I had to use Collider ins$$anonymous$$d of Collision, but none-the-less! :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
I have a question about the hit variable (C#) 1 Answer
C# Assigning EdgeCollider2D's Points 0 Answers