I want to understand this code in-depth

I am really digging down into the courses, thank for all the help and replies so far.

{
RaycastHit hit;

So RaycastHit is an struct (data type) and hit is the variable?

    bool hasHit = Physics.Raycast(GetMouseRay(), out hit);

What is out hit in this example? As in, what data type is it? Can I pass multiple parameters here?

It’s of type RaycastHit

You can read more about it here:

Yes

out is a keyword reserved by C#. A function can define parameters as ‘out’ parameters. This means that the function will set that value when we call it and we we will get something out. In this case, we have defined hit on the line just above it as RaycastHit and we will receive hit data from the function in that variable.

With newer C# versions, we can define the variable in the function call

bool hasHit = Physics.Raycast(GetMouseRay(), out RaycastHit hit);

Excellent explanations. My job is done here.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms