I’m having an issue with my raycast detection. I’ve tried to detect through both name and tag, but it ALWAYS returns true and runs whatever is in the if statement, even if it’s not meeting the if statement requirements. I’m at a loss as to what is the issue here. Here is my code for my raycasting.
public Transform RaycastLocation;
private Ray ray;
private RaycastHit hit;
public void Start()
{
ray = new Ray(RaycastLocation.position, RaycastLocation.forward);
}
public void Update()
{
if(Physics.Raycast (ray, out hit, 500))
{
if(hit.transform.name == "Duck");
{
Debug.Log(hit.transform.name);
hit.collider.gameObject.SetActive(false);
}
}
Debug.DrawLine (ray.origin, hit.point);
}