I am not sure why my third if statement is not working

EDIT: IT’S NOT THE THIRD IF THAT WASN’T WORKING, IT WAS THE SECOND “&&” THAT I INCLUDED THAT CAUSED THE SCRIPT TO NO LONGER WORK

The land would no longer develop once I added the second “&&” but would develop once I commented out the second “&&” and kept the third if statement enabled.

    //IF RAY HITS ROAD AND POWER POLE AND WATER PIPE, LAND IS DEVELOPED
       
            if (hitInfo.collider.CompareTag("RoadTag") && hitInfo2.collider.CompareTag("PowerPoleTag") && hitInfo3.collider.CompareTag("WaterPipeTag"))
            {

           
                // Check if ray from the un-developed land is hitting a collider (road collider, power pole collider)
         
                //ROAD
                if (hitInfo.collider != null)  //The inequality operator != returns true if its operands are not equal, false otherwise.

                {
                    //POWER POLE
                    if (hitInfo2.collider != null)
                    {

                        //WATER PIPE
                        if (hitInfo3.collider != null)
                   
                            Debug.Log("ray hit road"); //this debug is not being read
                            hitCount++;

                            StartCoroutine(StartDelay()); //wait 7 seconds for land to develop.
                            Debug.Log("Land Developed");

                        }

At line 9 (or even before line 3!) print all 3 colliders out, see what they are.

Also, because of the overloaded null check thingy in UnityEngine.Object you can shortcut those statements to simply:

if (hitInfo.collider)
{
....
1 Like

Those are the colliders on each of my three objects with their respective tag names

Oops sorry I made my thread wrong. The land would no longer develop once I added the second “&&” but would develop once I commented out the second “&&” and kept the third if statement enabled.