I’m trying to use raycasts to detect collisions, (because of “reasons”) and unity won’t compile my code.

		RaycastHit hit = Physics.Raycast(rayOrigin, Vector3.up * directionY, rayLength, collisionMask);
		if(hit){
			velocity.y = (hit.distance - skinWidth) * directionY;
			rayLength = hit.distance;
		}

it keeps giving me errors, saying (in order)

"Cannot implicitly convert type ‘bool’ to ‘UnityEngine.RaycastHit’

(referring to the first line of code I’m showing you)

and then says "Cannot implicityly convert type ‘UnityEngine.RaycastHit’ to ‘bool’

(referring to the line with the if statement)

So its saying hit is a boolean, and can’t be assigned as a RaycastHit,
but it literally says on the very next line that the hit variable was a RaycastHit variable, and as such, doesn’t work as a boolean for the if statement.

This makes no sense especially since the documentation says that a RaycastHit will return True if the ray hits anything and False if it doesn’t hit anything.

Am I calling the RaycastHit struct incorrectly or something?

RaycastHit hit;

if(Physics.Raycast (rayOrigin, Vector3.up * directionY, out hit, rayLength, collisionMask)){
	velocity.y = (hit.distance - skinWidth) * directionY;
	rayLength = hit.distance;
}

This is how I’ve always done it.