Question by 
               scarofsky · Aug 02, 2018 at 08:25 AM · 
                raycastcollidercollider2dcast  
              
 
              How to get my `collider2D.cast` work?
When I encountered this API : collider.cast(), I fell in love with it. It perfectly suits my need. However, I cannot detect any collision using the code below, and surprisingly, I haven't any demo code to my problem. Please help.
 // all gameObjects have collider2D, and rigidbody2D, and are on the same layer.
 // a circle is on the left side of a rectangle and is going to collide with the rectangle.
 
 void Update()
 {
     myCollider.Cast( Vector2.right, hitResults);
     if( hitResults != null)
     {
         //print all the collider info
     }
 
 }
 
              
               Comment
              
 
               
              Answer by neifiblue · Aug 20, 2018 at 12:47 PM
The length of RaycastHit2D[] hitRetults must be greater than 0 before use Collider2D.Cast. I hope it helps you!
         void Update()
         {
             int maxResultCount = 10;
             var hitResults = new RaycastHit2D[maxResultCount] 
             myCollider.Cast(Vector2.right, hitResults);
             if (hitResults[0] == true)
             {
                 //print all the collider info
             }
 
         }
 
 
              Your answer
 
             Follow this Question
Related Questions
How do you make one game object follow the shape of another game object? 0 Answers
CircleCast hit its origin... 0 Answers
Raycast collisions being detected along a non-existent curve(?) 1 Answer
Physic2D and Raycast2D on 3D Colliders problem... 0 Answers
Physics2D.Raycast from Collider edge hitting self? 0 Answers