Forum begins after the advertisement:


[Part 8] not an issue, but general question

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 8] not an issue, but general question

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13170
    Courtmaster
    Level 21
    Participant
    Helpful?
    Up
    0
    ::

    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?

    #13171
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

    #13179
    Courtmaster
    Level 21
    Participant
    Helpful?
    Up
    0
    ::

    Ah, gotcha. Thanks for the clarification. You’re a legend!

    #13184
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    No problem Courtmaster. Thank you for your support!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: