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:
So I’m assuming that he did not need to declare the bool or int because either:
- What he wrote was a specific shorthand notation somehow declaring everything he needed to declare without actually doing so or
- 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?