Help with Raycast and enemy.

hello guys. I have a problem with the Raycast. I made this script but when my player (tagged “soldier”) hits the line of Raycast but nothing happens.

#pragma strict

function Start()
{

}

function Update()
{
	var hit : RaycastHit;
	var direction = transform.TransformDirection(Vector3.forward);
	if(Physics.Raycast(transform.position, direction, hit))
	{
		if(hit.collider.CompareTag("soldier"))
		{
			print("Found it !");
		}
		else
		{
			Debug.DrawLine (transform.position, hit.point);
		}
	
	}
}

At a glance your code looks correct, so I think if you want an answer you need to provide more info. If you see a line then clearly you raycast works and hits something.

Does your soldier have a collider attached to him? Or did you place him in a layer that avoids ray casting?

And not an error but free code reduction is always nice; Transform has a ‘forward’ property that returns forward in world space, so you don’t have to transform it yourself.

Ok I solved it: D. I’m doing a fps in which an enemy shoot me if he sees me. In doing so the enemy shoots me only if I touch the line. How can I extend the range of vision? I had planned to do more lines … but I think it 's best option …