Problem with raycast distance

I want to have constant distance at which the raycasting should stop, but script ignore distance parameter. Help me please. Thank in advance.

void Update()
{
    float distance = 0.3f;
    Vector2 myvec = transform.position + target.position; 
    RaycastHit2D hit = Physics2D.Raycast(transform.position, -myvec,distance);
    Debug.DrawRay(transform.position, -myvec, Color.yellow);
    if (hit.collider != null)
    {
        print("hitted");
        if(hit.collider.gameObject.CompareTag("earth"))
        print("hit");
    }
}

void Update()
{
float distance = 0.3f;
Vector2 myvec = target.position - transform.position; // from transform to target
RaycastHit2D hit = Physics2D.Raycast(transform.position, myvec, distance);
Debug.DrawRay(transform.position, myvec.normalized * distance, Color.yellow);
if (hit.collider != null)
{
print(“hitted”);
if (hit.collider.gameObject.CompareTag(“earth”))
print(“hit”);
}
}