I've this script in UNITY to check if the hit
RayCastHid2D variable has some gameobject with hole
tag or a parent gameobject with hole
tag when I Raycast...
if (hit.collider != null && (hit.collider.gameObject.tag == "hole" || (hit.collider.gameObject.transform.parent.gameObject != null && hit.collider.gameObject.transform.parent.tag == "hole")))
Everything is fine until if (hit.collider != null && (hit.collider.gameObject.tag == "hole" ||
but when I enter (hit.collider.gameObject.transform.parent.gameObject != null && hit.collider.gameObject.transform.parent.tag == "hole")
it throws a NullReferenceException
....
But why?
It supposed to short circuit here hit.collider.gameObject.transform.parent.gameObject != null &&
if there's no parent gameobject!