I am trying to make a hexagonal movement system like in for the king, so I am casting a ray into the direction of my target until it hits another hexagon, but my while loop won’t run because unity says that my RaycastHit hitTwo does not have a value. Shouldn’t it work even if hitTwo is null?
FYI targetHex is the gameObject that I want to travel to, layermask is my layermask, currentHex is the gameObject that I am currently at, and otherRay is my ray.
My code:
while (hitTwo.collider.gameObject != targetHex) {
if (Physics.Raycast(otherRay, out hitTwo, float.MaxValue, layermask)) {
currentHex = hitTwo.collider.gameObject;
otherRay = new Ray(currentHex.transform.position, targetHex.transform.position);
print("found");
}
}