Hi there,
I’m following a tutorial on Youtube where the tutor is coding a script that detects whether the player has collided with obstacles. (I want to avoid overwhelming anyone who might read this post with information so I’ve simplified the coding that the tutor writes.)
In the script the tutor created a struct called CollisionInfo that contains four boolean variables called above,below,left and right:
public struct CollisionInfo{
public bool above,below;
public bool right,left;
}
He creates a reference to the struct at the top of the script by writing “CollisionInfo collisions” and then writes the following code further down the script involving an if statement which uses the “==” operators:
if (hit) {
collisions.above == directionY == 1;
collisions.below == directionY == -1;
}
The hit variable refers to a RaycastHit2D variable. Basically it is saying that if a raycast has hit an obstacle then hit is true. I’m finding it difficult to understand exactly what the two lines of code within the if statement mean? I assume that what it means is that if the directionY variable is equal to 1 then then the boolean value called “above” that resides in the CollisionInfo struct will equal to true?
I’ve looked for ages online trying to understand what the == operator means in this context but I still don’t understand.
I would appreciate if someone would be kind enough to explain what does two lines of code mean.
Kind regards