Question by
Payton-Dugas · Nov 30, 2016 at 06:31 AM ·
collidersraycasting
How to Access the Size component of a Collider from a Ray
Hello, I'm writing a collision detection script for my game in unity, and It would greatly help me to know the size of the object my ray hits.
This is what I would assume I could do.
I used "RayCastHit2D" to obtain the collider.
sizeX = hit.collider.size.x
But, there is apparently no component size for the collider. How can I get the size of the collider by only using the collider that the ray hit. I am quite confused, and cant wait to hear what the answer is. Thanks for the help!
Comment
I think you are looking for collider.bounds.size (https://docs.unity3d.com/ScriptReference/Collider-bounds.html). So you would do sizeX = hit.collider.bounds.size.x
Perfect, thanks that is just what I needed. I don't know why I couldn't find it before.