I have a raycast being fired from two points and I only want the player to fire when they can clearly see the tagged object. To do this I fire the ray from the gun to the target reticle.
The issue I’m having is that the ray is being drawn in the scene from the objects stated above. You can see in the attached image the drawn ray. Yet I still wasn’t getting the intended result. After some testing I discovered the code was working but the ray was not.
From the image you can see a green circle which I used to show where the ray was hitting.
Any ideas on what may be causing this issue would be great.
Code:
RaycastHit2D hit = Physics2D.Raycast(Hand.transform.position, camMove.e.transform.position, 20);
Vector3 direction = camMove.e.transform.position - Hand.transform.position;
Debug.DrawRay(Hand.transform.position, direction * hit.distance);
print(hit.transform.name);
var bullet = (GameObject)Instantiate(temp, hit.point, hit.transform.rotation);
return hit.collider != null && hit.transform.tag == "Enemy";
Attached image:
Moderators, if there is an issue with my question or the format of it could you please inform me what I am missing?