I’m attempting to use RayCastHit (see below) within Physics.Raycast, but Unity keeps giving me the “unassigned local variable” on hit. I was under the impression that the RaycastHit Type would be defined when called if valid, or null otherwise. Is my syntax incorrect? Any ideas on what I’m missing?
if (Input.GetButtonDown("Fire1"))
{
mouseButton1DownPoint = Input.mousePosition;
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, raycastLength, terrainLayerMask) )
{
print("Mouse Down Hit Terrain " + hit.point);
mouseButton1DownTerrainHitPoint = hit.point;
leftRectStart = hit.point;
mouseLeftDrag = true;
}
}
It should be noted that I’m porting code from another person’s Jscript.