Unexpected Errors - Need help & explaination plz

Part of a tutorial I’m following has this code in the script -

if(Physics.Raycast(r, out hit)
		{
			while(!passables.Contans(hit.transform.gameObject.name))
			{
				if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, out hit)
				{
					break;
				}
			}
		}

However, I’m getting these two errors -

“Assets/Scripts/CameraOperator2.js(71,43): BCE0044: expecting ), found ‘hit’.”

“Assets/Scripts/CameraOperator2.js(75,100): BCE0044: expecting ), found ‘hit’.”

Any ideas/suggestions ???

Missing a close bracket here:

alt text

The problem is that there is no need to use ‘out’ keyword in front of hit in JS (required in C#).

So raycast line becomes:

if(Physics.Raycast(r, hit))

and

if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, hit))

Now solving this will yield some other errors which are also solved here in this code below:

 #pragma strict
 
 public var selectionHighLight : Texture2D = null;
 public static var selection : Rect = new Rect(0, 0, 0, 0);
 private var startClick : Vector3 = -Vector3.one;
 private static var moveToDestination : Vector3 = Vector3.zero;
 private static var passables : String = ""; //{"Floor"};
 
 function Update()
 {
     CheckCamera();
     CleanUp();
 }
 
 function CheckCamera()
 {
     if(Input.GetMouseButtonDown(0))
     {
         startClick = Input.mousePosition;
     }
     else
     if(Input.GetMouseButtonUp(0))
     {
         if(selection.width <0)
         {
             selection.x += selection.width;
             selection.width = -selection.width;
         }
         if(selection.height <0)
         {
             selection.y += selection.height;
             selection.height = -selection.height;
         }
         startClick = -Vector3.one;
     }
     if(Input.GetMouseButton(0))
     {
         selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x, InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y));
     }    
 }
 
 function OnGUI()
 {
     if(startClick != -Vector3.one)
     {
         GUI.color = new Color(1, 1, 1, 0.2);
         GUI.DrawTexture(selection, selectionHighLight);
     }
 }
 
 static function InvertMouseY(y : float)
 {
     return Screen.height - y;
 }
 
 function CleanUp()
 {
     if(!Input.GetMouseButtonUp(1))
     {
         moveToDestination = Vector3.zero;
     }
 }
 
 public static function GetDestination(argumentVariableName : Vector3)
 {
     if(moveToDestination == Vector3.zero)
     {
         var hit : RaycastHit;
         var r : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
         
         if(Physics.Raycast(r, hit))
         {
             while(!passables.Contains(hit.transform.gameObject.name))
             {
                 if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, hit))
                 {
                     break;
                 }
             }
         }

		 if(hit.transform != null)
		 {
			 moveToDestination = hit.point;
		 }
             
             return moveToDestination;
     }
 }

Some of the things that are changed here are:

  1. Changed declaration of string

    private static var passables : String = “”; // This is how you initialize an empty string

  2. Changed HierarchyType.point to hit.point since there is no ‘point’ type under HierarchyTpe and I think what you are looking for is point of Raycast Hit.

  3. You need to provide a name to the variable that will be passed to your method as I’ve added below:

    public static function GetDestination(argumentVariableName : Vector3)