having trouble with recast infinity

geting error CS0117: UnityEngine.Physics' does not contain a definition for hit’

	//------------------------------------------------------------------------------------------

		if (Activate == true) {
			RaycastHit hit;
			float HitDistance;
			fwd = transform.TransformDirection(Vector3.back);
			if(Physics.hit(Vector3.zero, fwd, Mathf.Infinity))
				if (hit.collider.gameObject.name == "FighterRedTeam") {
				HitDistance = hit.distance;
					Target = hit.collider.gameObject;
					IsLockedOnBool = true;
					LockonGUIScript = Target.GetComponent<LockedOn> ();
					LockonGUIScript.IsLockedon = true;

				}

			if (hit.collider.gameObject.name == "DestroyerRedTeam") {
				Target = hit.collider.gameObject;
				IsLockedOnBool = true;
				LockonGUIScript = Target.GetComponent<LockedOn> ();
				LockonGUIScript.IsLockedon = true;
			}
		}

You try to call a method “hit” inside the Physics class which doesn’t exist. You want to call the “Raycast” method. If you want to aquire the hit information from the Raycast call you have to use one of the Raycast overloads which also have an “out” parameter of type RaycastHit, Just have a look at the documentation all the overloads are listed there, just scroll down. The second version in the documentation takes a starting position, a direction vector the “hit” out parameter, and the max distance. Actually parameters with an “=” equals sign are optional parameters which when not passed will simply have the value that is specified behind the equals sign. So if you want an infinite ray, just omit the max distance and it will automatically be infinite.

if(Physics.Raycast(Vector3.zero, fwd, out hit))

Though if you want to specify the max distance explicitly you can also do this:

if(Physics.Raycast(Vector3.zero, fwd, out hit, Mathf.Infinity))

Your next problem is you don’t have an opening curly bracket after your if statement. So it will only affect the next if statement that immediately follows but not the last one. So if the raycast doesn’t hit anything you would get a null reference exception in line 17 as “hit.collider” would not be set. Those two if statements should be inside a curly-bracket-block that comes after your Raycast if-statement.

ps: It’s a very bad habit to name a variable “fwd” when it doesn’t point forward at all. If the actual direction isn’t clear yet it’s better to use a neutral term like “dir” for direction. Even “vec” for vector would be better. Worse than non-descriptive names are names that are misleading. The same holds true for comments. It’s better to not write any comments than keeping wrong comments.