2D Raycast Not Working!!

Please can someone tell me why this isn’t working is seems so simple! I’ve got 2 years of coding experience but the n snippet just wont work. Can some please help me. Thank You!

This is pos and downn.

            downn = new Vector2(-transform.up.x  , -transform.up.y);

            pos = new Vector2(transform.position.x  , transform.position.y);

This is the part that wont work!

        RaycastHit2D hit = Physics2D.Raycast(pos, -downn , Mathf.Infinity);

        if (hit.transform.tag == "Untagged") {

            Debug.Log("Working");       

        }

Several things might be going on.

First off, you’re not testing whether you even hit anything. I think hit.transform.tag will return an error if you don’t. You can just add "hit " to the front, as RaycastHit2D can be implicitly cast to a Boolean which is true if it hit something.

Second… I’m a bit concerned about your pos variable. You’re setting it straight to your own transform. This will mostly likely result in your raycast simply hitting the originating object. If it has a tag on it, you’ll never reach your untagged objects.

Maybe check with:

if (hit) {

    Debug.log("Hit " + hit.collider.gameObject.name);

}