Interpreting Unity Documentation / Understanding dot operators, <>, ()

Hello, please bear with me as I am completely new to coding and Unity in general.

I was going through the video when Rick provided a challenge called “Stop Your Player Multi-Jumping” (4:12). He showed us the Unity Documentation for Collider2D.IsTouchingLayers and LayerMask.GetMask and asked to finish the logic to stop our player from multi-jumping.

I understood that you had to have some sort of an if statement where if the Player Collider touches the specified layer collider, you set some sort of boolean to false, where the boolean disables the jump.

The issue I had was with execution – no matter how many times I read through the documentation, I could not figure out how to phrase the wording and put the items together.

For example, here are the links below for the two methods mentioned earlier:

From looking at this, I thought “Okay, I don’t know how to proceed because Collider2D.IsTouchingLayers requires a bool, and LayerMask.GetMask requires an int. But if I set the int and bool, how do I connect it to the capsulecollider variable that I’m going to make? There just doesn’t seem to be the space for it in the declaration part of the Unity API.”

But Rick somehow didn’t need to declare the bool or the int below the public class, as he only needed one line in an if statement. His solution was:

        if (!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
        {
            return;
        }

So I’m assuming that he did not need to declare the bool or int because either:

  1. What he wrote was a specific shorthand notation somehow declaring everything he needed to declare without actually doing so or
  2. Dot operators or parentheses allow shorthand notation of int and bool.

Regardless, I came to the conclusion that I do not understand how to read Unity API after giving it my best shot and I do not fully understand the differences between the dot operator, <> and (). Could I ask someone to elaborate on these two things?

Dot operator is how you access the next object in an object.

() does a couple of things. Most of the time it’s how you declare the parameters in a method (or no parameters). The other thing is to cast an expression.

The <> is usually how to declare a type of a generic.

Most of those answers aren’t 100% accurate, but going deeper is likely to confuse you more. Unfortunately, I’m guessing most of that was technospeak but these are mostly fairly basic part of the C# language.

I’m going to suggest you go and take a look at some basic C# training. Here’s a half decent free one: C# Tutorial (C Sharp)

Thank you for the reply. I’ll try to go through it.

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

Privacy & Terms