In the future, please don’t paste screenshots of your code here. It makes it really difficult to help. See this post on how to format code in the posts
In your GridPosition
, the !=
operator is wrong. This will say that grid position a is != to grid position b only if both the X and Z values are different. if you say (10, 5) != (2, 5) it will return false, meaning they are the same. But (10, 5) == (2, 5) will also return false, meaning they’re not the same…
The way we usually do the override for !=
is to just negate ==
public static bool operator !=(GridPosition a, GridPosition b)
{
return !(a == b);
}
If you really want to do the full code bit, you need to change the &&
to ||
public static bool operator !=(GridPosition a, GridPosition b)
{
return a.x != b.x || a.z != b.z;
}
It’s for consistency’s sake that we negate ==
. If one says yes, the other should say no. In your case both could say no - which is inconsistent: How can a equal b and not equal b at the same time?