var LookAtTarget : Transform;
var rayRange = 10.0;
function Update ()
{
if (Physics.Raycast(transform.position, transform.forward, rayRange))
{
transform.LookAt(LookAtTarget);
}
}

It works great, but only in the z-direction(transform.forward), but i would like to have this ray casted in every direction x,y and z,. But i am not cableable of doing so. I have tried to insert Vector3 like so:

var LookAtTarget : Transform;
var rayRange = 10.0;
function Update ()
{
if (Physics.Raycast(transform.position, Vector3, rayRange))
{
transform.LookAt(LookAtTarget);
}
}

But with no luck.

So can you please help me here? I want my ray to be casted in ALL directions.

private const int DIRECTIONS_COUNT = 16;
private const int MAX_DISTANCE = 10;
public float GetDistanceToGround()
{
var distances = new List<float>();
foreach (var direction in GetSphereDirections(DIRECTIONS_COUNT))
{
Debug.DrawRay(transform.position, direction, Color.blue);
RaycastHit groundHitInfo;
if (Physics.Raycast(transform.position, direction, out groundHitInfo, MAX_DISTANCE))
{
distances.Add(groundHitInfo.distance);
}
}
return distances.Any() ? distances.Min() : MAX_DISTANCE;
}
private Vector3[] GetSphereDirections(int numDirections)
{
var pts = new Vector3[numDirections];
var inc = Math.PI * (3 - Math.Sqrt(5));
var off = 2f / numDirections;
foreach (var k in Enumerable.Range(0, numDirections))
{
var y = k * off - 1 + (off / 2);
var r = Math.Sqrt(1 - y * y);
var phi = k * inc;
var x = (float)(Math.Cos(phi) * r);
var z = (float)(Math.Sin(phi) * r);
pts[k] = new Vector3(x, y, z);
}
return pts;
}

you couldnt cast a ray in all directions, as that would be infinite… you could cast it in 10000 directions, or 1000 000, using one of these phi or a disco ball formulas: Loading... see the action script formula in the middle.

depending on the size of possible targets and their distance, you could calculate the number of racasts needed to see all of them… sphere casting is useful if they hide behind walls.

how can i debug ray then,
like, if i had to debug ray in single direction, i do:
if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), out hit, 5))
{
Debug.DrawRay (transform.position, transform.TransformDirection (Vector3.forward) * hit.distance, Color.yellow);
}

But I can’t able to debug ray on each direction?
Kindly help me in this regard.