Hello,
So I have an empty 2D scene with just a gameObject (Obj1) in it, which has a BoxCollider2D and this code:
RaycastHit2D hit = Physics2D.Raycast(transform.position + new Vector3(0, 0, 1f), transform.position + new Vector3(0, 0, 1));
if (hit.collider != null)
print(hit.collider.name);
else
print("Null000");
It should not hit anything and return “Null000”, but it always returns the name of this gameObject (Obj1).
So, what’s the problem, is this even the right way to cast a 2DRay? (I’m trying to cast it on the Z axis in a 2D game)
Thank you!