Forum begins after the advertisement:
-
::You might have covered this at some point, but if so then I missed it. Throughout the series with onTriggerEnter2D and the like, you typically add an underscore in front of “collision” or “other”:
private void OnTriggerEnter2D(Collider2D <strong>_collision</strong><em>)
{
if(<strong>_collision</strong></em>.CompareTag("Player")
What is the benefit of doing this instead of leaving it as is?
::Hi Courtmaster, there is no particular performance benefit, but some programmers prefer to name their variables differently depending on whether the variable is public or private, and the
is one way to differentiate between different kinds of variables. For example, the
is commonly used as a prefix for private variable:
public class MyScript {
public int myPublicVariable;
private int _myPrivateVariable;
}
In this case here, Matias or Kiefer probably decided to prefix _
to their function parameters to make it easier for them to distinguish between these and their class variables.
::Ah, gotcha. Thanks for the clarification. You’re a legend!
::No problem Courtmaster. Thank you for your support!
Advertisement below: