Help with If Statement

if(hit.collider == GameObject.FindGameObjectWithTag("Wall").transform.position)

This line has all sorts of problems.

GameObject.FindGameObjectWithTag is for finding a random object with a specific tag and storing it somewhere. You're already performing a raycast and getting info back via the "hit" variable, so there's no need to do any searching to begin with.

What you should instead do is something like this:

if (hit.collider.CompareTag("Wall"))

That line of code checks to see if the object hit by the raycast has a tag of "Wall." I'm assuming that's what you meant to do in the first place.

As for the .transform.position you originally had at the end... that just has me perplexed. I can't even begin to imagine why you tacked that on there unless you were just trying random things out to see if the code would work.

/r/Unity2D Thread Parent