x


C# out hit for raycasthit - why is the out needed, what does it go

I notice that RaycastHit is called differently for JS vs C#... In C#, the hit is actually out hit ... what does the out do, and why is it needed?

more ▼

asked Apr 07 '12 at 09:37 PM

ina gravatar image

ina
3.3k 492 551 602

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

As far as I know, the Out gives you the info about what it hit, like the distance to the hit, the name of the object it hit, the point where it hit, and so on.

It can be very helpful in some cases where you wanna know if a laser hit a friendly target or an enemy, for example.

more ▼

answered Apr 08 '12 at 12:20 AM

kyon77 gravatar image

kyon77
1 1 2 2

(comments are locked)
10|3000 characters needed characters left

Most function arguments are passed by value -- that is, you pass a copy of the original value, rather than the variable itself. Changes made to that copy won't be reflected in the original variable unless your code does so explicitly.

Some functions accept arguments that are passed by reference -- instead of a copy, you pass the original variable itself. Changes made in the called function will be reflected in the original variable.

C# and UnityScript both typically pass by value, unless the called function explicitly tells the compiler to pass by reference. C# is unique in that it requires coders to explicitly pass by reference on both sides of the call -- I assume the idea is to make sure that you know you're doing so, as it can sometimes lead to confusion.

Ultimately, both languages are doing the same thing. C# just has a slightly different syntax for doing so.

more ▼

answered Apr 07 '12 at 11:07 PM

rutter gravatar image

rutter
5.2k 2 11

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4178
x1536
x161
x83

asked: Apr 07 '12 at 09:37 PM

Seen: 685 times

Last Updated: Apr 08 '12 at 12:20 AM