- Home /
2D collisions in Unity 4.3?
So, I'm following a tutorial on youtube that uses javascript. I figured I was well versed enough in C# that I could figure out how to rewrite things, and have been doing fine, until it got to collisions.
What does this for loop even mean, and how can I write it in C#? for ( var contact in c.contacts ) { }
Taken from here: https://www.youtube.com/watch?v=poCBXJ1RWgI#t=34m27s
Alternatively, if you know of a better c# focused tutorial, a link would be appreciated.
Answer by D3ltaVyyb · May 05, 2014 at 07:36 PM
Hey,
Okay 'c' in the video is an array of Vector 2 contact points. ( Vector2(x,y) ) ... So in C#, getting them in a loop will be:
foreach (Vector2 contact in c.contacts) { //rest of code should work fine here }
Here's the Microsoft C# reference: foreach, in (C# Reference)
Ah, yeah I've never used foreach before. It seems contact should be a ContactPoint2D rather than Vector2, but now it works. Thanks.
Your answer
Follow this Question
Related Questions
WHY UNITY HAVE THIS PROBLEM ? 0 Answers
Distribute terrain in zones 3 Answers
[RESOLVED] Pressing the "Z" key to make him go through certain terrain objects? 1 Answer
How can I detect a collision between two clones and delete them both? 1 Answer
How to fix the vibration while colliding and the suspension after jumping? 0 Answers