Raycasting won't work when looking down

Hey,

So I’ve put together a script and works good but when I use the Debug.DrawRay I can see that when looking down the ray disappears. Any help?

#pragma strict

var showGUI : boolean = false;

var posMiddle = 0.0;
var posCenter = 0.0;

var tagCheck : String = "Wood";

function Start()
{
	posMiddle = Screen.width / 2;
	posCenter = Screen.height / 2;
}

function Update() 
{
	var hit : RaycastHit;
	var foundHit : boolean = false;
	
	foundHit = Physics.Raycast(transform.position, transform.forward, hit);
	
	if(foundHit && hit.transform.tag == tagCheck)
	{
		showGUI = true;
	}
	else
	{
		showGUI = false;
	}
	
	Debug.DrawLine (transform.position, hit.point, Color.cyan);
}

function OnGUI()
{
	if(showGUI)
	{
		GUI.Box (Rect (posMiddle - 75,posCenter + 20,150,25), "Press E To Pickup");
	}
}

the logic of the script looks fine.

My guess would be that either as you look down you are hitting a character collider whose position is on top of the camera and so the line is being drawn between the camera location and the camera’s location again, making it invisible. If this is the case you should change your Raycast to include a Player layermask.

Seems like an unlikely solution though.

Post an answer if you find out the issue.