private RaycastHit2D hit;
hit = Physics2D.Raycast(myObject.transform.position, Vector2.zero);
if (hit.collider != null)
{
Debug.Log(hit.collider.name);
}
private RaycastHit hit;
if (Physics.Raycast(myObject.transform.localPosition, myObject.transform.forward, out hit))
{
Debug.Log(hit.transform.name);
Debug.DrawRay(hit.point, myObject.transform.forward, Color.red);
}
// Don't forget to add colliders on the object you want to hit with the raycast